Jump to content

Can there be too many .js files in a project structure / Phaser game?


Gardevoir
 Share

Recommended Posts

Hi there!

So basically, to cut to the chase. I have an issue that isn't really causing problems as of yet, but I'm worried that it might in the future and I'd rather not get into a habit now that might come back to bite me later. My question is simply as stated above, can there be such a thing as too many JavaScript files in a Phaser game project? I understand the answer to this is yes, but how many would you advise as the cut off point?

To help with this I'll provide a little context. I'm currently making a project at the moment as a sort of test bed for a new game idea, but currently my planning has led me to create an extremely split up approach to the game, whereby each object is being created as an extension of either Phaser.Sprite, Phaser.Group etc. Using these, I'm creating prefabs and defining their variables and methods within them and then controlling these as a wider whole throughout. Now, to keep the project structure relatively clean and manageable I'm splitting these object's into separate .js files in a "class" style approach, but this has led so far to me having at least 14 .js files for the objects alone and at least 7 .js files for the game's states.

The reasoning for my worry is that I'm sure that having 21 or possibly more .js files is going to cause an extremely long page load time or bottleneck for the end user. Although, I'm not moving between pages so caching and reloading scripts might not be a large issue, but I'm still unsure if this is maybe a bad practice and approach to creating a Phaser game and to a greater extent, HTML5 games in general. But, saying that, would it fix any possible bottlenecks if I were to create a "published" build whereby I place all of my game's logic into one large, minified .js file? Is there any advice on this subject? I know it's fairly open and possibly more opinion based rather than definitively answerable, but I'm extremely confused and any help offered would be appreciated. :)

Link to comment
Share on other sites

You should as a matter of practise always concat and minify your game source when publishing it. It gets the js http request count down to just 1, and being minified (and ideally gzipped on the server as well) it will shave potentially hundreds of KB off the download size.

Unless you're using the source code as a means to train others, who may need to see the source in its natural state, I can't think of any significant benefits to including the source 'as is' in its raw form.

Having said that, 21 js files is nothing. I wouldn't worry about such a smaller number personally.

Link to comment
Share on other sites

Ah I see Rich, yes it makes perfect sense to minify the final published build. I was just unsure, as I'm relatively new to the world of HTML5 games development and so it's all a rather new experience for me when it comes to working practices. Thank you for your help! :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...