Browse - Programming Tips - How do I preload an image using jQuery?

Date: 2012jul4
Updated: 2019jan8
Language: javaScript
Platform: web

Q.  How do I preload an image using jQuery?

A.  Create and use an Image object in your ready() function:

function preloadImage(url) { (new Image()).src = url; } $(document).ready(function() { preloadImage('images/myimg.jpg'); });