Unable to update webserver cached static flask Javascript files


#1

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.


#2

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.


#3

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.


#4

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.


#5

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.


#6

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?


#7

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.


#8

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.


#9

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