Preloading images using the <link> HTML tag
I believe most visitors to this question are looking for the answer, "How can I preload the image before rendering the page?" and the best solution for this problem is to use <link> because the <link> is able to block further page rendering. See proactive
These two values โโof the rel value (the relationship between the current document and the linked document) are most relevant for this problem:
- prefetch : load the specified resource when the page is displayed
- preload : load this resource before starting to render the page
Therefore, if you want to load a resource (in this case, an image) before starting the <body> rendering process, use:
<link rel="preload" as="image" href="IMAGE_URL">
and if you want to load the resource during the <body> rendering but plan to use it dynamically later and donโt want to bother the user with the loading time, use:
<link rel="prefetch" href="RESOURCE_URL">
mertyildiran Jan 22 '17 at 7:43 on 2017-01-22 07:43
source share