browserquest / BrowserQuest

Continuing the development of Mozilla BrowserQuest
http://browserquest.herokuapp.com
Other
444 stars 220 forks source link

Download static assets in a web worker #134

Open Aaron1011 opened 11 years ago

Aaron1011 commented 11 years ago

Currently, the static assets for BrowserQuest (music and images in this case) are download when the Login button is clicked. If we were to start fetching them once the page had loaded, we could probably increase the speed of logging in. Of course, the risk is that the user decides not to play, meaning we've download the files for nothing.

justinclift commented 11 years ago

Good thinking. Any idea how we should do this?

Aaron1011 commented 11 years ago

@justinclift: On second thought, it will probably need to be done in a jQuery document load handler. Web workers can't manipulate the DOM, and can only communicate with the main thread using strings and JSON. What I'll need to do is move the calls to loadAudio and loadSprites in game.js from the run method to an onload handler.

Aaron1011 commented 11 years ago

@justinclift: Do you know where in the code would be best to add the handler? The Game instance has to be in scope, because both loadAudio and loadSprites mutate it.

justinclift commented 11 years ago

Not sure atm. I'm trying to dedicate this weekend to getting a different side project back up to date (GlusterFlow), so I'm trying to keep my head in Python mode. :smile:

Aaron1011 commented 11 years ago

@justinclift: Ah, okay :smile:.