admin 管理员组文章数量: 1086019
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
2 Answers
Reset to default 2You 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">
本文标签:
版权声明:本文标题:javascript - The resource was blocked due to MIME type (“texthtml”) mismatch (X-Content-Type-Options: > nosniff) - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744018244a2519321.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论