user235273
user235273

Reputation:

On what basis are javascript files cached?

On what basis does javascript files get cached? Say I load a file with the name 'm-script.js' from one site and on another website I use the same name 'm-script.js' but with different contents. Will the browser fetch the new one, or just look at the name and load it from the cache? The urls for both the m-script.js file are different (obviously).
Thanks.

Upvotes: 3

Views: 1302

Answers (3)

Domenic
Domenic

Reputation: 112907

Since nobody has mentioned it yet, there is a lot more involved in HTTP caching than just the URI. There are various headers that control the process, e.g. Cache-Control, Expires, ETag, Vary, and so on. Requesting a different URI is always guaranteed to fetch a new copy, but these headers give more control over how requests to the potentially-cached resource are issued (or not issued, or issued but receive back a 304 Not Modified, or...).

Here is a detailed document describing the process. You can also google things like "caching expires" or "caching etag" for some more specific resources.

Upvotes: 1

Sanghyun Lee
Sanghyun Lee

Reputation: 23072

Browsers cache files by their full URI.

This thread( How to force browser to reload cached CSS/JS files? ) will help you to understand.

Upvotes: 2

Paul
Paul

Reputation: 141897

If the url is different the cached copy will not be used. A new request will be made and the new file will be downloaded.

There would be a huge security and usability issue with the browser if a Javascript file cached from one website was used on another.

Upvotes: 4

Related Questions