1

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

NakedBrunch
  • 48,713
  • 13
  • 73
  • 98

2 Answers2

4

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
  • 9,999
  • 2
  • 44
  • 54
  • Alison is asking about client-side caching which is different subject. – Konstantin Tarkus Mar 25 '09 at 21:23
  • 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 Mar 25 '09 at 21:39
3

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

Konstantin Tarkus
  • 37,618
  • 14
  • 135
  • 121