I need a php function that will preload the product images in WooCommerce not the gallery. I have a plugin that I can insert the image url's one by one. However, since I have over 600 products is it possible via php to preload all of the images sitewide as their respective pages are accessed?
My website is https://www.theherbsplace.com
ASKER
ASKER
add_action( 'wp_head', function(){
$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
echo '<link rel="preload" as="image" href="'.$featured_img_url.'"/>';
});
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
1) Image preloading, means images leave disk + cache in memory.
Note: If you mean preloading into a browser, this is a very bad idea, as mobile users will instantly abandon your site when they get an alarm of your site eating up battery life + saturating their network connection + then eating up memory with all your images.
2) Eventually with no image access, images leave memory.
3) You can do this to force all your images into memory...
Open in new window
Which will access all images once, loading them into Kernel buffers.
4) Doing #3 will only work as expected if you have enough memory to hold all your images.
5) Doing #3 will eventually dump images from cache based on other file access, if your memory is low.
Said differently, #3 loads all images into Kernel buffer memory.
Then as other files are accessed, they enter Kernel buffer memory, so eventually if an image is never used by a visitor, it will be evicted from Kernel memory.