Created
April 29, 2013 02:02
-
-
Save anonymous/5479307 to your computer and use it in GitHub Desktop.
Preload all images in your CSS files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
var i, image, j, matches, rules, sheet; | |
for (i = 0; i < document.styleSheets.length; ++i) { | |
sheet = document.styleSheets[i]; | |
if (sheet.rules) { | |
for (j = 0; j < sheet.rules.length; ++j) { | |
rules = sheet.rules[j]; | |
if (rules.style && rules.style.backgroundImage) { | |
matches = rules.style.backgroundImage.match(/url\((.*)\)/); | |
if (matches) { | |
image = new Image; | |
image.src = matches[1]; | |
} | |
} | |
} | |
} | |
} | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment