Unable to update webserver cached static flask Javascript files


Hi, apologies for the odd topic title … here is the problem I am seeing.

I have a simple python/Flask app with a basic template. I have some test javascript files sitting in my static folder.

All works well, templates are rendered, jquery is working, and my local .js files are being imported properly.

Took me a long time to get to the root of this but whenever I modify my local static .js file, it seems that the webserver is holding on to a cached version and I cannot find a way to update this old version. I can see through the browser developer console that the cached .js resource does not match the file on disk.

I have restarted the webserver, restarted the workspace, and have confirmed that there is no other file in my workspace (thinking that maybe there is a duplicate and I am not looking at the right one).

Can someone patiently explain what is happening here and how I can resolve?

I assume that this is because the browser has a cached version of the file. But why is this being treated differently to other files that I can update on the fly?

Thanks in advance.


I know it is probably too late to reply, but this is the only search that google returns regarding this problem. i am having the same problem and i have no idea how to fix it. it’s hard to believe that so few people encountered this problem. every time i edit my js script i fanatically save it 20 time, restart the server and it randomly appears to work. i’ve wasted 4 hours today just because i thought my problem was in the python logic when in fact it was my javascript.


I’m not certain but I think the problem is with the update of static files
in the browser cache.

If you change the static js files on the server, for some reason the
browser does not update its stored copy. Restarting the server does not
always seem to trigger an update to the browser static cache.

In dev I have been able to force a workaround by clearing my browser cache
and reloading the page.

However I’m not sure what will happen in prod. How do you ensure that the
users will get the functionality you roll out if the browser cache has to
be cleared this way?

Not sure if this is browser specific. I am using Chrome.

Good luck.


A year later, and I just ran into this problem.
Did you ever figure out a way to get the static file to update?

I’m also using chrome.


I had to clear the chrome cache to get around this issue yesterday. Seems to happen rarely. I now normally browse with inspector on and caching disabled.


Thanks… I was able to get things to refresh by adding a ?test=test to all my url calls to the files.
But that seems like a terrible solution…
Is this purely a c9 issue?


Im not sure if it occurs elsewhere. I suspect it is a chrome issue more than c9, but I don’t know or have any evidence to back that up. I stopped and started my instance on c9 and the problem continued, but clearing the browser cache resolved it. I feel like that points to chrome.


I wonder if i deploy this app to a real server, if the problem is going to persist for other chrome users using the app. Right now, I was just trying this out, as opposed to my usual way of running a express/nodejs server.


Did you guys find any better solution to the problem, i am having the same problem. I dont use c9 though.


I’m experimenting the same issue here. Some news? I’m using Firefox and I’m sure it’s the same problem, the first time I use send_file/send_file_from_directory, flask sends me the correct file, but after that, the file sent is the same every time in a lot of tests.

When I do the same in a Private Window of my browser, file get ‘updated’ the first time.

The behavior is that now I have two different files to download, the one in the cache of the Private window and the one in the cache of the normal browser. It doesn’t matter what I do, those files get updated once after lots of times I try to download them.

There has to be something to clear the browser cache from Python or Flask (at least executing a Javascript).


My problem was with the cached files sent by flask. I solved it by using cache_timeout=-1 as a parameter of the function send_file_from_directory.
I also changed the parameters of my Firefox browser to not save cache in my app. It works nice on chrome.