4

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.

5

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

3
  • 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.. – Amit Kumar Gupta 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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