当我的应用程序最初加载时一切正常,并且在 Chrome 中,控制台错误为 0。当我按下浏览器刷新时,我收到以下错误:
Refused to execute script from 'http://localhost:50001/dist/vendor-es5.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
我也收到“main-es5.js”的相同错误
错误是从我这里的index.cshtml 文件生成的:
@section scripts {
<script src="~/dist/vendor-es5.js" asp-append-version="true"></script>
<script src="~/dist/main-es5.js" asp-append-version="true"></script>
}
改变
<script type="text/javascript" src="~/dist/vendor-es5.js" asp-append-version="true"></script>
仍然给出相同的错误。
我的index.cshtml 文件位于views/home 中 dist 目录位于 clientapp
例如,如果我将脚本 src 上的引用更改为 ./clientapp/dist/vendor-es5.js,那么该应用程序仍然可以在第一次正确加载,但是当我按下刷新时,我没有得到任何控制台错误,但页面仍然不刷新。大家有什么想法我下一步应该去哪里。
最佳答案
首先,请确保我们已经启用了以下HTTP
功能,这使得IIS能够正确处理静态文件的请求。
它还可能与客户端构建工具的设置有关,例如 Webpack
。
Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled
此外,在某些 ReactJs 应用程序中,使用 App.use
方法也可能是导致此类问题的原因。
app.use(express.static(__dirname + "/static"));
请引用以下链接。
loading a bundle.js file from webpack changes mime type to text/html
Refused to execute script from because its MIME type (...) and strict MIME type (...)
Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled
Refused to execute script, strict MIME type checking is enabled?
关于javascript - IIS为js文件返回text/html,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61951949/