NakedBrunch
NakedBrunch

Reputation: 49423

CSS Image Caching

In terms of client-side image caching, is there a difference between the following:

**Option #1**
<div style="background:url('myimage.jpg');display:none;"></div>

and

**Option #2**
<div id="myimage"></div>

style.css
#myimage {
     background:url('myimage.jpg');
     display:none;
}

EDIT: I'm not sure if it matters but the above DIVs are first loaded on another page with style="display:none;"

Upvotes: 1

Views: 2142

Answers (2)

Konstantin Tarkus
Konstantin Tarkus

Reputation: 38428

No. Also note that some browsers won't cache graphics ih hidden elements (regrardless of whether you hide them directly or hide one of their parent elements).

Upvotes: 3

Chris Hynes
Chris Hynes

Reputation: 10249

No. Client caching is controlled by headers returned from the server in the request for the image, not the css.

As an aside, if you're looking for image caching, I highly recommend using a CDN. Amazon's CloudFront makes this easy and cheap.

Upvotes: 4

Related Questions