Skip to content

Instantly share code, notes, and snippets.

@mattbontrager
Created April 17, 2013 22:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattbontrager/5408135 to your computer and use it in GitHub Desktop.
Save mattbontrager/5408135 to your computer and use it in GitHub Desktop.
Preloading images with 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