tdc
tdc

Reputation: 5464

Chrome won't stop caching scripts, even when caching disabled

I am working on a PHP and JavaScript app. I make modifications to my JS, refresh Chrome, and it is not using the most recent script. It appears to be caching.

I have "disable caching" checked in Dev Tools, and I even tried an extension Cache Killer, but Chrome STILL caches my script.

This behavior is not occurring in Safari or Firefox, without any plugins.

Any ideas?

Upvotes: 0

Views: 374

Answers (1)

LiveLongAndProsper
LiveLongAndProsper

Reputation: 359

You can usually force the browser to load a fresh copy of a URL by making it "new" using something like a new parameter value in the URL.

Example:

<script type="text/javascript">
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src", "yourfile.js?random=" + new Date());
document.getElementsByTagName("head")[0].appendChild(script);
</script>

This will load a new instance of the file "yourfile.js" everytime because we append the date and time of "now", which will always be new.

(this post was written as an answer because I cannot write comments at the moment)

Upvotes: 3

Related Questions