'chrome fails to load SOME scripts & stylesheets with ERR_INVALID_HTTP_RESPONSE (for a flask app on linux (debian))

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.



Solution 1:[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'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Huy Doan