Occasionally .js files are served with text/html content type
What steps have you taken to resolve the issue?
I am trying the solution here:
Not sure yet if it works.
What are the steps to reproduce the issue?
I’m serving an app using the NiceGUI Python framework behind a Cloudflare tunnel. Occasionally my app fails to load and inspecting it shows incorrect mime types for Javascript files. See screenshot.
Your screenshot shows the returned files start < so likely there is an error, challenge or some other HTML response being returned in place of the js, hence the change in type. Check if you have any challenges enabled in your WAF or due to your security level, or aim to trap this and reload the page (to trigger the challenge page to the user).
I see. I am using Zero Trust Access to require a login before showing the page. This login does show up, but when it redirects to my app I get the above failure occasionally. The only thing that seems to fix it is purging cache at Cloudflare. If I go directly to my app bypassing Cloudflare and login, it of course works.
So perhaps some issue with Zero Trust interaction? Not sure what exactly I need to do in the app, as it 80% of the time works fine even with the login.
Thanks for the advice. Turns out I had a middleware proxy that was changing that .js content, but it was meant to have no-cache headers. Instead, those wrong pages were being cached.