views:

423

answers:

2
+1  Q: 

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;"

+4  A: 

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.

Chris Hynes
Alison is asking about client-side caching which is different subject.
Koistya Navin
Client caching is controlled by the cache headers on the request. Yes, CDN != client caching, but it is also very useful in situations when you are worrying about caching because of perf.
Chris Hynes
+3  A: 

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).

Koistya Navin
Which browsers don't cache graphics in hidden elements?
Alison
Like IE for example
Koistya Navin