Skip to content

Instantly share code, notes, and snippets.

@jhrr
Last active August 29, 2015 13:56
Show Gist options
  • Save jhrr/8794592 to your computer and use it in GitHub Desktop.
Save jhrr/8794592 to your computer and use it in GitHub Desktop.
JQuery image preloader that should work correctly with the hashing mechanism from django-compressor.
function preLoadImages () {
$.get($('link[rel="stylesheet"]')[0].href, function(data){
r = /url\(['|"]?(\S+\.(gif|jpg|jpeg|png)[^'(]*)['|"]?\)/ig;
while (match = r.exec(data)){
var cacheImage = document.createElement('img');
cacheImage.src = match[1];
}
});
}
preLoadImages();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment