CSS Preload Images

This is an interesting technique for preloading graphics. Resources: One here. This guy originated it, but it’s pulled down now.

  1. #preloadedImages {
  2.        width: 0px;
  3.        height: 0px;
  4.        display: inline;
  5.        background-image: url(path/to/image1.gif);
  6.        background-image: url(path/to/image2.gif);
  7.        background-image: url(path/to/image3.gif);
  8.        background-image: url(path/to/image4.gif);
  9.        background-image: url();
  10. }

This is much easier than using JS to do it. I need to experiment with it more.

This entry was posted in Uncategorized and tagged . Bookmark the permalink.

9 Responses to CSS Preload Images

  1. Adaptiv CSS says:

    Great solution, I assume I just put an empty div at the end of my page…

  2. alex says:

    this doesnt work with firefox 2, but it does with safari

  3. xPheRe says:

    Neither does work under Firefox 3.
    Only loads the last declared ‘background-image’ :(
    Nice idea, though ;)

  4. Glen Lipka says:

    Hmm, Ill have to work on a different technique.

  5. alex says:

    im guessing it doesnt work cos css2* doesnt support multiple background images.

    my solution was to create a div (i think i set it’s display:none) on the page with preloaded images with width=1 height =1 (height/width=0) seems to not load the image on some browsers.

    from what i remember, it was compatible with firefox 2/3, safari 3, ie6/7

    http://www.songbirdestate.com.au

  6. danreb says:

    I encountered a situation that I need to preload not only images but including swf file that will be used in other pages of our company site, so I ended up using iframe to do it, If someone have a better solution for this please help.

    Here what I done:

    in my css here’s my code

    .preload {
    position: absolute;
    top: -9999px;
    left: -9999px;
    height: 20px;
    width: 20px;
    display:inline;
    overflow: hidden;
    }

    then at the bottom of my page before the closing body tag i insert the iframe in the div with a class preload and insert there the iframe that loads the html document consisting of all images and flash file that I need to preload and will be used in other pages of my site, here how I do it.


    <iframe src=

  7. danreb says:

    Continuation:

    <iframe src=

  8. danreb says:

    see the actual page http://www.teamquest-inc.com.ph

    it works fine in all browser i tested

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>