Created
August 5, 2016 20:05
-
-
Save cobbman/f08cc0c9e86797eb6a5f4820b767eb8e to your computer and use it in GitHub Desktop.
Preload js, css, and images with AJAX
This file contains hidden or 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
# Please reference this article for the full description: https://perishablepress.com/3-ways-preload-images-css-javascript-ajax/ | |
window.onload = function() { | |
setTimeout(function() { | |
// XHR to request a JS and a CSS | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'http://domain.tld/preload.js'); | |
xhr.send(''); | |
xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'http://domain.tld/preload.css'); | |
xhr.send(''); | |
// preload image | |
new Image().src = "http://domain.tld/preload.png"; | |
}, 1000); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment