Search code examples
javascriptflaskcachingstatic

Python Flask 304 response on reload


I am having an issue with a flask app that I can't seem to track down.

The first time I load the index page of my flask app, all resources load correctly. If I reload the page, I get 304 errors on some resources that are loaded from my static directory. These resources have not changed, so the 304 is correct, but it seems like there is not a local resource in the cache.

As you can see in the developer console of chrome, the resources that are red, are ones that have 304'd, and if I click on one of them to view their contents it appears as though no cached version of the resource exists:

No data found from cached resource

This breaks the functionality of the page. If I hard reload, or clear cache and hard reload, the resources load just fine. Also if I just disable cache in chrome, then the page always loads fine, but this requires the developer console to always be open. This flask app did not always do this. Something with flask or chrome has changed since when it was written and I cannot figure it out.

I have also tried tricks like others have recommended with putting date modified tags onto the url, but this doesn't change the outcome. It seems like the local cache of chrome is broken.

This also happens in Microsoft Edge and Firefox.

What is happening!!! This is driving me mad!!!


Solution

  • Try downgrading the version of both Flask and Werkzeug (v2.0.2 worked for me).

    I was using version 2.1.1 and I was having the same issue, but I had another app that used those two libraries that was not failing, and it was using version 2.0.2 of both of them.

    Downgrading did the trick for me.

    Hope it helps!