-
-
Save crossai-2033/729152 to your computer and use it in GitHub Desktop.
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
/*! | |
* JavaScript preload() function | |
* Preload images, CSS and JavaScript files without executing them | |
* Script by Stoyan Stefanov – http://www.phpied.com/preload-cssjavascript-without-execution/ | |
* Slightly rewritten by Mathias Bynens – http://mathiasbynens.be/ | |
* Demo: http://mathiasbynens.be/demo/javascript-preload | |
*/ | |
function preload(arr) { | |
var i = arr.length, | |
o, | |
d = document, | |
b = d.body, | |
isIE = /*@cc_on!@*/0; | |
while (i--) { | |
if (isIE) { | |
new Image().src = arr[i]; | |
continue; | |
}; | |
o = d.createElement('object'); | |
o.data = arr[i]; | |
o.width = o.height = 0; | |
b.appendChild(o); | |
}; | |
}; | |
// Example: | |
preload([ | |
'http://tools.w3clubs.com/pagr2/1.sleep.expires.png', | |
'http://tools.w3clubs.com/pagr2/1.sleep.expires.js', | |
'http://tools.w3clubs.com/pagr2/1.sleep.expires.css' | |
]); |
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
/*! | |
* $.preload() function for jQuery | |
* Preload images, CSS and JavaScript files without executing them | |
* Script by Stoyan Stefanov – http://www.phpied.com/preload-cssjavascript-without-execution/ | |
* Slightly rewritten by Mathias Bynens – http://mathiasbynens.be/ | |
* Demo: http://mathiasbynens.be/demo/javascript-preload | |
* Note that since this script relies on jQuery, the preloading process will not start until jQuery has finished loading. | |
*/ | |
$.extend({ | |
preload: function(arr) { | |
var i = arr.length, | |
isIE = $.browser.msie, | |
d = document, | |
b = d.body, | |
o; | |
while (i--) { | |
if (isIE) { | |
new Image().src = arr[i]; | |
continue; | |
}; | |
o = d.createElement('object'); | |
o.data = arr[i]; | |
o.width = o.height = 0; | |
b.appendChild(o); | |
}; | |
} | |
}); | |
// Example: | |
$(function() { | |
$.preload([ | |
'http://tools.w3clubs.com/pagr2/1.sleep.expires.png', | |
'http://tools.w3clubs.com/pagr2/1.sleep.expires.js', | |
'http://tools.w3clubs.com/pagr2/1.sleep.expires.css' | |
]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment