strict mime type checking is enabled, refused to execute script from '<url>' its mime type ('text/plain') is not executable, and

Viewed 12066

I am newbie in Django, and i was working on a Django app. And i used "media" folder to keep my css and javascript files (i know it's not a good practice) but it was working. Some lines of code

<link href="/media/shop/bootstrap//css/bootstrap.min.css" rel="stylesheet">
<link href="/media/shop/bootstrap//css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="/media/shop/themes/css/bootstrappage.css" rel="stylesheet" />

<script src="/media/shop/themes/js/jquery-1.7.2.min.js"></script>
<script src="/media/shop/bootstrap//js/bootstrap.min.js"></script>
<script src="/media/shop/themes/js/superfish.js"></script>

However what happened i don't know after somedays(today) when i opened this project again and tried to run on local host then i am getting error in console like this
this.
After clicking on the link present in error it displays my javascript file but not executing it.
And the most weired thing is that when i executed the same file in other system(also on local host) after transferring the same folder then it is working, no any such error in console. And the same project(website) is also hosted on internet and when i open that site online in my system again then also no any such error. However when i replace

<script src="/media/shop/themes/js/jquery-1.7.2.min.js"></script>

with

<script type="javascript" src="/media/shop/themes/js/jquery-1.7.2.min.js"></script>

then error not comes in console but it is still not working. I don't think there is any problem with browser setting because i checked in 3 different browsers but it is showing same thing.
Any suggestion how to solve this issue and how to disable mime type checking ?

3 Answers

Try adding the following code to your settings.py

import mimetypes

mimetypes.add_type("text/javascript", ".js", True)

It's a solution someone told me. Sadly, it does not come with any explanation.

The script should be type="application/javascript"

Check your Windows registry key.

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

HKEY_CLASSES_ROOT\.js
    Content Type    REG_SZ    text/plain

Update the key as following, it works for me.

C:\>reg add HKCR\.js /v "Content Type" /t REG_SZ /d application/javascript
Related