Explain Codes LogoExplain Codes Logo

Resource interpreted as Script but transferred with MIME type text/plain - for local file

javascript
mime-type
local-development
server-configuration
Alex KataevbyAlex Kataev·Jan 24, 2025
TLDR

For scripts misinterpreted as text/plain, set the correct Content-Type to text/javascript on your server. Using a local server for development is highly recommended. Here's a Python’s built-in server oneliner:

# A simple Http server to rescue w/ correct MIME types # Open http://localhost:8000 - voila! python3 -m http.server

Ensure your JavaScript files have a .js extension. Access them via localhost address in your browser.

In-depth diagnostics

We flash a flashlight on your problem. If you are stumbling across the MIME type warning in Google Chrome, you are dealing with local script files. Chrome defaults to text/plain when it fails to recognize the expected MIME type.

In some rare cases, your Visual Studio might be acting naughty and adding registry entries that treat your beloved .js files as plain text. Quick check? Make sure the type attribute is not text/plain within your script tags. Instead, it should be type="text/javascript".

How to tame servers and browsers

Messing around with the local environment

You can use local development servers like WAMP, MAMP, or XAMPP which come preconfigured with the correct MIME types.

A note for Visual Studio Users - disable browser link feature to prevent MIME type complications.

Tackling IIS Configuration

If you are charing ahead with IIS, ensure the Static Content feature is enabled on your IIS Manager. You can hop to the web.config file and scribble this in:

<staticContent> <!-- Yes, it insists on calling JavaScript files --> <!-- in a language it can understand --> <mimeMap fileExtension=".js" mimeType="text/javascript" /> </staticContent>

Taming Google Chrome

Check chrome://flags/ for settings that could send the MIME types haywire.

Did you check the Extensions? They can be the mystery guest causing the ruckus. Try switching to incognito mode to rule this out.

Dive deeper: advanced solutions and precautions

But I am an Admin, I'll edit the Registry

If you have the superpowers of a system admin, you can safely modify registry keys. But remember, with great power comes great responsibility. Only resort to registry editing if you've exhausted all other options.

The Registry Lifeline: Look for .js under HKEY_CLASSES_ROOT. Set the Content Type to text/javascript.

When You're Walking On Fire: If there are PerceivedType entries that are playing the party-pooper. Show them the door.

Save Yourself, Do Backups: Never a good idea to wade into the registry without backing up first!

Stand on the shoulders of Giants: If you're especially unsure, do what humans do best, ask professionals for help.

Large projects, larger headaches

Have a massive number of scripts for your project? Save yourself a headache, use build tools to do the MIME type checks for you.

Ensure there is no conflicting script causing a ruckus in your project.

Say Hi! to the community

If Murphy's Law haunts you and the issue is persistent, time to hit the community forums. Don't be shy, Chrome and IIS forums have seen it all before.