calabash
calabash

Reputation: 453

Flask - Javascript file requires multiple page refresh to load net::ERR_INVALID_HTTP_RESPONSE 200

I have a Flask app that relies on javascript for certain functionality. The javascript file loads fine sometimes and other times I get an error in the console:

GET http://localhost:5000/static/js/sm4sb.js net::ERR_INVALID_HTTP_RESPONSE 200

When this happens the javascript is not loaded. I then have to refresh the page multiple times until the console does not show this error.

I read somewhere that putting this in my config.py file should fix it, but it doesn't

SEND_FILE_MAX_AGE_DEFAULT = 0

Elsewhere someone suggested adding this:

@app.after_request
def add_header(response):
    response.headers['Cache-Control'] = 'no-cache, no-store'

But when I do that I get an error

AttributeError
AttributeError: 'NoneType' object has no attribute 'vary'

Note that the issue is with Chrome, it works without an issue running in Firefox.

EDIT: I have found a few references that suggest this is a Flask issue and to downgrade to an earlier version. I will try that and report back.

Upvotes: 0

Views: 225

Answers (3)

Sadique Khan
Sadique Khan

Reputation: 320

Upgrade your flask

pip install flask --upgrade

Upvotes: 0

calabash
calabash

Reputation: 453

After submitting a bug to the Werkzeug team they said to upgrade from version 2.1.1 to the latest 2.1.2.

Doing this fixed the issue.

So to clarify I now run Python 3.10.4, Flask 2.1.2 and Werkzeurg 2.1.2 and this issue no longer occurs.

Upvotes: 1

Emrah Diril
Emrah Diril

Reputation: 1755

This page on CSDN (link is via google translate) suggests the workaround is to downgrade Werkzeug (not flask) to version 2.0.2.

(Btw, according to the page on CSDN, the real issue is with Chrome version 73)

Upvotes: 0

Related Questions