Search code examples
javascripthtmlrenderingpreload

How could JavaScript possibly *pre*-load an image if the <script> is already loaded?


Looking at this question about preloading images with js, I assumed it was a misunderstanding about client vs server js rendering. However, it was closed as a dupe of another highly voted question about preloading images with js.

My understanding is that by the time the <script>s are executing (late in the page render, as per: Where should I put <script> tags in HTML markup?), that any benefit to preloading images are nullified, since you are already past the load stage, so you aren't pre-loading, but simply loading.

What benefits are expected by pre-loading via js?
Is it conceptually possible that images loaded via js are in an way pre-loaded?


Solution

  • Is it conceptually possible that images loaded via js are in an way pre-loaded?

    My current understanding is that the images are loaded before they're displayed on the page e.g. images in a gallery that the user has to open.

    What benefits are expected by pre-loading via js?

    More responsive sites.