ritmas
ritmas

Reputation: 365

browser caching: same remote filename in different sites

I have several different sites in different hosts and I use the same JS file in all of them which is loaded from one and only remote host. For instance,

One single JS filename my.js is stored at someotherhost.net.

This filename is loaded in several different pages (sites):
somedomain1.net/home.html
somedomain2.net/home.html
somedomain3.net/home.html

Browsing through these sites browser caches my.js. But will it use the same cache for all different sites?

Or maybe it doesn't matter whether the requested filename is named the same, stored in single remote host and loaded in different pages, browser will have different caches?

How browser caching works?

Upvotes: 3

Views: 804

Answers (1)

johnhunter
johnhunter

Reputation: 1836

Yes. The browser will cache each unique url, provided there are no headers that tell it not to.

Your file should have one entry in the browser cache even if it is requested from a number of referring pages. Once cached from one site the browser will use the cached version for all the others so speeding up the page load.

This is the idea behind loading JavaScript libraries from a CDN (content delivery network). If you load jquery from http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js there's a good chance the user already has it in their browser cache so it will load instantly.

Upvotes: 3

Related Questions