Jump to content

Preload - only loading or also downloading?


3ddy
 Share

Recommended Posts

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

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).

Link to comment
Share on other sites

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

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.

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...