CSS Throwdown: Preload Images without JavaScript
Post #373 categorized as Presentation, last updated on Mar 16, 2009
Tagged with css, images, javascript, notes, optimize, tips, tricks
Clean, easy, effective. You don’t need no stinking JavaScript to preload your images. Nope. Try some tasty CSS and (X)HTML instead! Here’s how.. (only two steps!)
Step 1 — Place this in your CSS file:
div#preloaded-images {
position: absolute;
overflow: hidden;
left: -9999px;
top: -9999px;
height: 1px;
width: 1px;
}
Step 2 — Place this at the bottom of your (X)HTML document:
<div id="preloaded-images">
<img src="http://perishablepress.com/image-01.png" width="1" height="1" alt="" />
<img src="http://perishablepress.com/image-02.png" width="1" height="1" alt="" />
<img src="http://perishablepress.com/image-03.png" width="1" height="1" alt="" />
</div>
..and that’s a wrap! All images are preloaded and ready for calling as you please. Completely valid, standards-compliant image preloading via CSS and (X)HTML!!
Share this..
Related articles
- A Way to Preload Images without JavaScript that is SO Much Better
- Pure CSS: Better Image Preloading without JavaScript
- Preloading Images with CSS and JavaScript
- Better Image Caching with CSS
- Drop-Dead Easy Random Images via PHP
- Focus on the Details: Optimizing Images for Humans and Machines
- Feed your Image via Atom or RSS
#1 — Arjan Eising
This will not work as you expect…
The images are loaded, but that is because they are in the XHTML code.
The CSS does not apply any background to the
div-element, because you ‘overwrite’ the background with an empty one.