3ddy Posted June 14, 2016 Share Posted June 14, 2016 Hello, probably I have a very simple (and stupid?) question. When I load some sprite atlases in my preload function are they downloaded from the server when the preload is executed (and then loaded to memory), or during preload loop they are only loaded to device memory because they were downloaded earlier (before game.load function)? I need to optimise my game to download assets on many loading screens, not all at once. I did some googling but didn't find anything about downloading assets Any advice, links appreciated - thanks Link to comment Share on other sites More sharing options...
Str1ngS Posted June 14, 2016 Share Posted June 14, 2016 You're going into browser mechanics here, If the asset is not available in the browser cache, it will downloaded to your device. And depending on the cache headers/configuration set on both the client and the server each consecutive load of the same asset will be either loaded from cache(prefered) or downloaded. This article goes a bit deeper into browser caches: https://gtmetrix.com/leverage-browser-caching.html As for Phaser itself, apart from the asset having a different HTTP status code (HTTP 304 instead of 200) the asset will be loaded into memory for the current session, and you'll notice no difference (apart from loading speed). 3ddy 1 Link to comment Share on other sites More sharing options...
3ddy Posted June 14, 2016 Author Share Posted June 14, 2016 You said that if the asset is not available in the browser cache, it will be downloaded - OK I get it, but it will be downloaded from the server (checked if available in browser cache) when I call game.load, not earlier (during some game initialisation or something) - right? Link to comment Share on other sites More sharing options...
mattstyles Posted June 14, 2016 Share Posted June 14, 2016 Nope, it'll be loaded when you ask for it, the browser will not attempt to evaluate the JS (or the HTML, I dont think) to preload any necessary assets that may be needed some time in the future. HTTP2 will work slightly differently and your server will actually be able to push assets at the browser that it knows (or thinks) will be needed later but for now, for most people, if you want them preloaded you have to handle that yourself. Most preloaders work by initiating requests, which then get cached so that when you request them later, when you actually want them, they come from cache. 3ddy 1 Link to comment Share on other sites More sharing options...
Recommended Posts