最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - The resource was blocked due to MIME type (“texthtml”) mismatch (X-Content-Type-Options: > nosniff) - Stack

programmeradmin7浏览0评论

File structure

index.js:

app.set("view engine", "ejs");

app.use(express.static("public"));

app.use(
  bodyParser.urlencoded({
    extended: true,
  })
);

chat.ejs

<body>
    <h1><%= (roomName) %></h1>
    
    <div id="video-grid">

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

while loading, error displayed

"The resource from “http://localhost:5000/chat/Aishu%20study/Aneesa/script.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)."

It works if I keep everything in the same html file. can someone help me with this? I'm not sure what the problem is

File structure

index.js:

app.set("view engine", "ejs");

app.use(express.static("public"));

app.use(
  bodyParser.urlencoded({
    extended: true,
  })
);

chat.ejs

<body>
    <h1><%= (roomName) %></h1>
    
    <div id="video-grid">

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

while loading, error displayed

"The resource from “http://localhost:5000/chat/Aishu%20study/Aneesa/script.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)."

It works if I keep everything in the same html file. can someone help me with this? I'm not sure what the problem is

Share Improve this question edited Sep 24, 2020 at 7:05 kiranvj 34.2k8 gold badges75 silver badges79 bronze badges asked Sep 24, 2020 at 6:53 AneesaAneesa 411 gold badge1 silver badge3 bronze badges 2
  • is script.js really a javascript file? also how e error message mentions some /xyz/ subdirectory in the url path, what most likely happened is that the path is incorrect and it matches some other general endpoint returning an html file you did not post in your answer – Krzysztof Krzeszewski Commented Sep 24, 2020 at 6:57
  • this is the error message "The resource from “localhost:5000/chat/Aishu%20study/Aneesa/script.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)." – Aneesa Commented Sep 24, 2020 at 6:59
Add a ment  | 

2 Answers 2

Reset to default 2

You should include Your public path like this:

app.use(express.static(__dirname+ '/public'));

And then implement your scripts and styles like this:

<script src="/script.js">

The issue lays in incorrect pathing in your application, you see the way you included script.js in the html file may have been correct if the paths were relative to the same folder. To be precise the ways you could define it are

The one you used "script.js" file is located in the same folder as the current page, it does not work the way you want it, since you are accessing the script tag from the localhost:5000/chat/Aishu%20study/Aneesa/xx url

<script src="script.js">

The "script.js" file is located in the scripts folder in the current folder

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

The "script.js" file is located in the scripts folder at the root of the current web

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

The "script.js" file is located in the folder one level up from the current folder

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

And lastly the one you should be using, the "script.js" file is located at the root of the current web

<script src="/script.js">

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论