function wp_image_preload() { echo '<link href="' . get_template_directory_uri() . '/img/treasure-map3.svg" rel="preload" as="image">'; } add_action( 'wp_head', 'wp_image_preload', 5 );
This function preloads an image as a resource link in the head of the HTML page. Specifically, it creates a <link> element that tells the browser to preload the resource
What is preloading images for?
Preloading images can be useful for improving performance and optimizing page loading.
Preloading images allows the browser to start loading resources before they are actually needed. By preloading images, users can see page content faster because assets begin loading immediately, even if they are not yet fully visible on the screen.
Preloading images can help optimize page loading on mobile devices where network connections may be slow or unreliable.