[javascript] Refused to execute script, strict MIME type checking is enabled?

Why am I getting this error in console?

Refused to execute script from 'https://www.googleapis.com/customsearch/v1?key=API_KEY&q=flower&searchType=image&fileType=jpg&imgSize=small&alt=json' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

This question is related to javascript json

The answer is


My problem was that I have been putting the CSS files in the scripts definition area just above the end of the Try to check the files spots within your pages


I had my web server returning:

Content-Type: application\javascript

and couldn't for the life of me figure out what was wrong. Then I realized I had the slash in the wrong direction. It should be:

Content-Type: application/javascript

After searching for a while I realized that this error in my Windows 10 64 bits was related to JavaScript. In order to see this go to your browser DevTools and confirm that first. In my case it shows an error like "MIME type ('application/javascript') is not executable".

If that is the case I've found a solution. Here's the deal:

  1. Borrowing user "ilango100" on https://github.com/jupyterlab/jupyterlab/issues/6098:

I had the exact same issue a while ago. I think this issue is specific to Windows. It is due to the wrong MIME type being set in Windows registry for javascript files. I solved the issue by editing the Windows registry with correct content type:

regedit -> HKEY_LOCAL_MACHINE\Software\Classes -> You will see lot of folders for each file extension -> Just scroll down to ".js" registry and select it -> On the right, if the "Content Type" value is other than application/javascript, then this is causing the problem. Right click on Content Type and change the value to application/javascript

enter image description here

Try again in the browser."

After that I've realized that the error changes. It doesn't even open automatically in the browser anymore. PGAdmin, however, will be open on the side bar (close to the calendar/clock). By trying to open in the browser directly ("New PGAdmin 4 window...") it doesn't work either.

FINAL SOLUTION: click on "Copy server URL" and paste it on your browser. It worked for me!

EDIT: Copying server URL might not be necessary, as explained by Eric Mutta in the comment below.


I solved my problem by adding just ${pageContext.request.contextPath} to my jsp path . in stead of :

 <script    src="static/js/jquery-3.2.1.min.js"></script>

I set :

 <script    src="${pageContext.request.contextPath}/static/js/jquery-3.2.1.min.js"></script>

In my case I had a symlink for the 404'd file and my Tomcat was not configured to allow symlinks.

I know that it is not likely to be the cause for most people, but if you are desperate, check this possibility just in case.


This result is the first that pops-up in google, and is more broad than what's happening here. The following will apply to an express server:

I was trying to access resources from a nested folder.

Inside index.html i had

<script src="./script.js"></script>

The static route was mounted at :

app.use(express.static(__dirname));

But the script.js is located in the nested folder as in: js/myStaticApp/script.js refused to execute script, meme type checking is enabled. I just changed the static route to:

app.use(express.static(path.join(__dirname, "js")));

Now it works :)


In my case it was a file not found, I typed the path to the javascript file incorrectly.


Python flask

On Windows, it uses data from the registry, so if the "Content Type" value in HKCR/.js is not set to the proper MIME type it can cause your problem.

Open regedit and go to the HKEY_CLASSES_ROOT make sure the key .js/Content Type has the value text/javascript

C:\>reg query HKCR\.js /v "Content Type"

HKEY_CLASSES_ROOT\.js
    Content Type    REG_SZ    text/javascript

I hade same problem then i fixed like this

change "text/javascript"

to

type="application/json"

I accidentally named the js file .min instead of .min.js ...


Add the code snippet as shown below to the entry html. i.e "index.html" in reactjs

_x000D_
_x000D_
<div id="wrapper"></div>_x000D_
<base href="/" />
_x000D_
_x000D_
_x000D_


i had the same issue and the problem was that i was missing a slash in my path.

i had

and to fix it i only needed to add the slash in between jquery-ui and jquery-ui.min:

  <script type="text/javascript" src="js/jquery-ui/jquery-ui.min.js"></script>

hope this helps :D


Try to use express.static() if you are using Node.js.

You simply need to pass the name of the directory where you keep your static assets, to the express.static middleware to start serving the files directly. For example, if you keep your images, CSS, and JavaScript files in a directory named public, you can do as below -

i.e. : app.use(express.static('public'));

This approach resolved my issue.

Thanks,


If you have a route on express such as:

app.get("*", (req, res) => {
  ...
});

Try to change it for something more specific:

app.get("/", (req, res) => {
  ...
});

For example.

Or else you just might find yourself recursively serving the same HTML template over and over...