beuleal Posted June 26, 2014 Share Posted June 26, 2014 hello guys, sry my dump question, but im seeing some phaser's project and they dont use window.onload at start of the js file. Why they do that? And, how it works? Link to comment Share on other sites More sharing options...
lewster32 Posted June 27, 2014 Share Posted June 27, 2014 window.onload is only needed if you include your JavaScript at the top of the html page (i.e. in the <head> tag) - you'd do this to load your JavaScript up-front to do something important with your page before it's loaded. If you don't need to do this (which turns out to be the case most of the time) you can put your JavaScript at the bottom of the page (usually just before the closing </body> tag) and this will mean by the time the JavaScript loads, the rest of the page has already loaded. It's better practice to put your JavaScript at the end of the page, as this makes the page perceptibly faster to open - the browser will render the page as soon as it has enough to make sense of the contents, but loading script files 'blocks' the browser until they've loaded. By having the browser render the page first, then start loading and executing the scripts, the user spends less time watching a white page loading. PBMCube 1 Link to comment Share on other sites More sharing options...
rich Posted June 27, 2014 Share Posted June 27, 2014 Internally Phaser uses DOMContentLoaded, as we're only interested in the page and scripts being ready, not all page dependencies (which is what window.onload waits for). Link to comment Share on other sites More sharing options...
beuleal Posted June 27, 2014 Author Share Posted June 27, 2014 Nice! Thanks for u all replies! Link to comment Share on other sites More sharing options...
Recommended Posts