How do I split my web applications?

Recommended Posts

So generally speaking you have projects.  Lets say you have some phaser games like `football` and `shooter`


You also have other systems which are wider in scope.  Say `Leaderboard` or `AdSystem`. 


What is the modern way of dealing with this? Right now I am trying an IFrame.  So essentially  `Leaderboard` is just a webpage, and `shooter` will load `Leaderboard` into an Iframe.  This sucks for a lot of reasons though. I know it is not the best way. 


It is like, `Leaderboard` does not want to be a web page.  It wants to just be a javascript API and hence the confusion. 


I am somewhat aware of Modular JS, but I have not went fully external. I know it would involve a lot of refactoring on my side which I am happy to do but I am not sure going in that direction will solve my problem? 

I want to say "new Leaderboard" when I need it rather than use a Script tag to load in leaderboard incase I happen to need it..... Not least because then index.html pages become a pain to maintain. 

Any ideas here? 


Thanks for reading! 

Share this post

Link to post
Share on other sites

If you want to use something like:

var leaderBoard = new LeaderBoard(containerElement, "/my-leader-board-content/");

You have to create a "class" that abstracts away the details of requesting the leaderboard data:

// This example assumes you are using jQuery for the AJAX request, but you// can use any other library for this or even roll your own with XMLHttpRequest.function LeaderBoard (parent, url) {        // Create an element to contain the leaderboard:    this._container = document.createElement("div");        // Add it to the parent element:    parent.appendChild(this._container);        // Fetch the leaderboard data:    $.ajax({url: url}).done(this.update.bind(this));}LeaderBoard.prototype.update = function (data) {        // If your URL returns some HTML:    this._container.innerHTML = data;};

In this example, the URL should not deliver a full HTML page. Instead it would give just the HTML for the leader board, without any HTML header and stuff like that. This also assumes you get the leader board content from your own server.


I'm not sure this is what you want, but your question is much too vague to answer with any certainty. It all depends on where you get the data from and in what form. It would also help to know how you organize your code... Mind-reading is not my speciality.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.