6

I have a flask app running on Linux and working correctly under firefox. For chrome, it only works if the cache is disabled!? But i want my website to work correctly without every user having to disable caching.

This is how the template HTML header looks:

<!-- Bootstrap & CSS  -->
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/fontawesome-free-6.1.1-web/css/all.min.css" >
<link rel="stylesheet" type="text/css" href="/css/app.css">

{% if css_file %}
<link rel="stylesheet" type="text/css" href="{{ css_file }}">
{% endif %}

<!-- JQuery -->
<link rel="stylesheet" type="text/css" href="/bootstrap/css/jquery-ui.css" >
<link rel="stylesheet" type="text/css" href="/bootstrap/css/jquery-ui.min.css" >
<script type="text/javascript" src="/bootstrap/js/jquery.js"></script>
<script type="text/javascript" src="/bootstrap/js/jquery-ui.min.js"></script>

<!-- Bootstrap JS -->
<script type="text/javascript" src="/bootstrap/js/bootstrap.min.js"></script>

<!-- local JS -->
<script type="text/javascript" src="/scripts/language.js"></script>
{% if js_file %}
<script type="text/javascript" src="{{ js_file }}"></script>
{% endif %}

And yes all files exist in the static folder (because it works in firefox) And flask is initiated like this (which is the default):

# create and configure the app
app = Flask(__name__, static_url_path='', static_folder='static', template_folder='templates')

Chrome (dev tools->network): enter image description here

Chrome (dev tools->network)(with cache disabled), same for firefox (cache enabled): enter image description here

Could someone give me a hint on how to analyse further what the problem is? Could it be related to the response of flask for static files? Or do I have the wrong header order? Or is it a problem with the scripts/ stylesheets, do they have the wrong configuration? So the question is how to fix this for chrome without disabling the cache.

And no I do not have Adblock or similar addons installed.

user1911091
  • 1,219
  • 2
  • 14
  • 32
  • I have the same problem - Flask app + Google Chrome (I would say, the problem appeared since update to version 100, but I'm not sure). Same behaviour - when loading page without cache, it's loaded correctly, after that I hit F5 on the same page (load with cache) and it loads only HTML (without resources - CSS, JS, images, ... or partially) resources are attemted to load, but fail with net::ERR_INVALID_HTTP_RESPONSE (no response at all, no response headers). The problem is also in Incognito window (no addons). – Michal Vašut Apr 22 '22 at 06:42
  • Does this answer your question? [Python Flask 304 response on reload](https://stackoverflow.com/questions/71890593/python-flask-304-response-on-reload) – Dan Stewart Jul 13 '22 at 20:20

2 Answers2

1

I think this issue related to Chrome, but I don't have time to dig deeper into it. My workaround is include no-store in Cache-Control header:

@app.after_request
def add_header(response):
    response.headers['Cache-Control'] = 'no-cache, no-store'
Huy Doan
  • 131
  • 1
  • 4
0

It's a bit late but had the same issue and it got fixed by upgrading flask, you can check what needs to be upgraded with

pip list --outdated

if you have multiple outdated packages (this will upgrade everything)

pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_}