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

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Alison is asking about client-side caching which is different subject.
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.
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).

1 Comment

Which browsers don't cache graphics in hidden elements?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.