Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

A javascript snippet that will preload all images defined in the styles sheets.

View preload.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
(function(){
var styles, matches, match, url, img = new Image(), loaded = [];
function forEach(a,c){if(a&&c){for(var i=0;i<a.length;++i){c.call(a[i])}}};
forEach(this.styleSheets, function(){
forEach(this.rules, function(){
forEach(styles=this.style, function(){
if(this.toString() !== 'background-image')return;
if(!(matches=styles[this].match(/url\([^\)]+\)/g)))return;
forEach(matches, function(){
if(!(match=this.match(/url\(([^\)]+)\)/)))return;
if(loaded.indexOf(url=match[1]) !== -1)return;
loaded.push(img.src = url);
});
});
});
});
}).call(document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.