I have a photo gallery page hosted on CMS (Squarespace) that has some of its own scripts that load thumbnails asynchronously.
The actual large images, however, are not predefined, so I decided to add it to my own script to make the browser load these large images into the cache in the background, for example:
(function($) { var cache = []; // Arguments are image paths relative to the current page. $.preLoadImages = function() { var args_len = arguments.length; for (var i = args_len; i--;) { var cacheImage = document.createElement('img'); cacheImage.src = arguments[i]; cache.push(cacheImage); } } })(jQuery) $(window).load(function(){ $.preLoadImages( "/picture/1.jpg", "/picture/2.jpg", //etc. ); });
I put my code in $ (window) .load (), because it is a background script, and it doesnβt matter that it even runs at all, itβs just to improve performance.
However, I think this script somehow blocks the preloading of its own CMS script thumbnails.
I'm right? And most importantly, is there a way to dictate that my script runs only after all other scripts on the page have been launched?
amuses
javascript jquery asynchronous blocking preloading
andy
source share