Wrong content-type on .js files

What is the name of the domain?

redacted.org

What is the issue you’re encountering

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.

It seems there are quite a few reports of this problem on the forum: https://community.cloudflare.com/search?q=wrong%20MIME

Is there some reason this happens? The solution I’m using seems to be papering over the problem if it works.

Screenshot of the error

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).

1 Like

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.

Have a look at the content of the files by clicking the link in the debug window to see what they are returning when you get the error.

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.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.