browser-cachetampermonkeyversionsmultiple-versions

Browser Caching Versions in Google Chrome with Tampermonkey


I have a question about caching versions of imported files (via web requests) in Google Chrome:

Let's say I have script.js, whose URL is: http://www.getscripts.com/script.js (URL contents arbitrary after "http://", because TamperMonkey imports over the HTTP protocol)

If I import the script in Tampermonkey using @require, I want to use a query string for its version to avoid caching.

Caching versions:

Let's say, that I first @require the 1st "version" of the script (created it, and inserted initial content), by giving the require a URL of http://www.getscripts.com/script.js?v=1, so I pass in the URL a query string of the version v=1, and that the script file of version v=1 was not cached already.

I make some changes to the code of script.js, and the script that the URL provides also gets updated (I use surge.sh).

Then, I change my @require URL to: http://www.getscripts.com/script.js?v=2, so I pass in the URL a query string of the version v=2

Then I make some more changes in the code, make sure the URL gets the updated file, and give the @require my initial URL with v=1: http://www.getscripts.com/script.js?v=1

Question:

The script file that will be returned (via an HTTP request) - will it be of version 1, or 2?

What I'm doing is trying to force-download a new version of my script file, after I update the script's code, since Tampermonkey caches script files without re-downloading them, unless there was some changes made in the URL of the @require (what does the HTTP request).


Solution

  • This was solved by forcing the browser to download a new version of the script by adding a version parameter to the script's URL, as suggested by wOxxOm above.