Jump to content

Loading Javascript Files in order


royibernthal
 Share

Recommended Posts

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

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

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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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