Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

When a css/js refers on a webpage it is first downloaded to client machine. From the next time it is referred from browser cache (if it presents). Please tell me

  1. What happens when multiple sites refer a css/js having same name.
  2. What happens when sub-domains refer a same css/js
  3. What happens when many websites refer css/js from specified cdn like google or some other place.

Please tell me, in such cases, whether browser refers copy from cache or it makes local references according to main sites or something else.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

What happens when multiple sites refer a css/js having same name.

If they are served from different URLs then the browser will consider them to be different resources and fetch both.

What happens when sub-domains refer a same css/js

If they are served from different URLs then the browser will consider them to be different resources and fetch both. If they refer to the same file then the browser will download the file on the first request and then use a cached copy of the file if appropriate (i.e. not expired).

What happens when many websites refer css/js from specified cdn like google or some other place.

They will download the file on the first request and then use a cached copy for subsequent requests (if it is not expired).

share|improve this answer
4  
Unless the CSS or JS files are served over HTTPS or with the "no-store" Cache-Control header, in which case they are never cached. –  Nick May 31 '11 at 15:19
    
@Nick, I am working over HTTPS only. still js is being cached.. –  articlestack Jun 15 '11 at 5:15
    
@articleshack Apparently HTTPS content is cached by default in IE, and also if the page's Cache-Control header has a non-zero max-age. See this question. –  Nick Jun 15 '11 at 7:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.