royibernthal Posted May 14, 2014 Share Posted May 14, 2014 It's become tiring to have to concat and minify all of my javascript files in order to be able to test properly on mobile. How do I load the js files in order in a way that is compatible with all browsers and devices? Link to comment Share on other sites More sharing options...
Heppell08 Posted May 14, 2014 Share Posted May 14, 2014 I thought using states did that after you added the initial state inside the index.html in the order necessary.States use a boot, preload, menu then game.Maybe look into that and configure from there to your needs. Look in resources/project templates in the src for the state like set up. Link to comment Share on other sites More sharing options...
stasuss Posted May 14, 2014 Share Posted May 14, 2014 js files are loaded by the browser asynchronously and automatically. the reason to minify and concat all the files is in reducing the amount of data transferred to the client and the amount of requests processed by the server. but you can use something like require.js or Phaser's http://docs.phaser.io/Phaser.Loader.html#script Link to comment Share on other sites More sharing options...
royibernthal Posted May 14, 2014 Author Share Posted May 14, 2014 What does loaded asynchronously mean? One after the other? I understood from rich that I had many problems on mobile because I didn't explicitly load my files in order. What does require.js do? Phaser's Loader.script() - is call back called after the script tag is generated or after the script file has been loaded? Link to comment Share on other sites More sharing options...
jpdev Posted May 14, 2014 Share Posted May 14, 2014 What does loaded asynchronously mean? One after the other? No, the opposite. The browser sends out all requests and inserts the file in the order that they return.This is normally the order in which they are specified, but it does not have to be. If this happens, your javascript may fail (it runs as if the files were loaded in a different order - so if phaser.js is suddenly at the bottom, nothing will work.) This is why for production releases putting all files into one big file is necessary. The file should then be minified, but this is just for bandwidth reasons. This is why you should embrace grunt - with a grunfile in the project directory (which takes one minute to setup, if you have done it before) you just type "grunt" into the command line and get a deployable directory within seconds. (clean old release directory, concat all js, minify all js, copy resources, copy js.. done) Link to comment Share on other sites More sharing options...
royibernthal Posted May 14, 2014 Author Share Posted May 14, 2014 I'll look into grunt, but isn't there a way to load synchronously? At least for the development phase. Link to comment Share on other sites More sharing options...
jpdev Posted May 14, 2014 Share Posted May 14, 2014 If you develop on a local webserver (or even on the filesystem) the order is almost guaranteed to be correct.(Only through "the tubes" of the internet it's possible that one file takes longer to fetch then the others below it) Link to comment Share on other sites More sharing options...
Heppell08 Posted May 14, 2014 Share Posted May 14, 2014 I'll look into grunt, but isn't there a way to load synchronously? At least for the development phase. I use grunt for my games and find it does help alot. You may like to look at Codevinskys set up for creating a phaser game set up with grunt and many other useful things: http://www.html5gamedevs.com/topic/5127-generator-phaser-official-yeoman-generator-for-phaser-projects/ Link to comment Share on other sites More sharing options...
Recommended Posts