Flask application not reflecting new JS changes
<p>I have the following code in my Flask server:</p>

<pre><code>    res = Response(resp, mimetype='text/plain')
    res.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
    res.headers["Pragma"] = "no-cache"
    res.headers["Expires"] = "0"

    return res
</code></pre>

<p>On the client side I have some javascript code (in folder static/JS/) that I am constantly editing while fixing bugs and so on. However the changes I make to the javascript code (example adding an alert or debug statement) do not execute when I refresh the page in a regular chrome window (even when I kill the browser and restart it). This means it continues to run an older (cached copy). The refresh works properly when I use an incognito window. Is there a way so that even the regular browser window can always fetch the latest code? I am concerned that in a production environment the browser will used cached copies and cause an issue.</p>

<p>One trick for making sure the browser does not cache a file is to change the url when the file changes. That can be done without changing the filename, by appending a query:</p>

<pre><code>&lt;script src="myscript.js?version=7"&gt;
</code></pre>

<p>Or, even better:</p>

<pre><code>&lt;script src="myscript.js?timestamp=2837482.2456"&gt;
</code></pre>

<p>You can make a function which generates the URL with the file's actual timestamp. That way, browser will cache it as long as it does not change.</p>

<p>If you are wondering... the query will be ignored. It does not affect static files.</p>

javascript python caching flask