javascript - IIS为js文件返回text/html,为什么?

标签 javascript iis mime-types

当我的应用程序最初加载时一切正常,并且在 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能够正确处理静态文件的请求。
enter image description here
它还可能与客户端构建工具的设置有关,例如 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/

相关文章:

azure - 在 IIS web.config 中使用动态 IP 安全设置时忽略某些 IP 或 IP 范围

javascript - IIS 中的 AngularJS 路由

php - 电子邮件中 ​​.eml 文件的 MIME 类型是什么

php - nginx : Resource interpreted as Stylesheet but transferred with MIME type text/html 无法识别 css 和图像

javascript - then(function) 没有得到 angularjs 中返回的 promise 值的更新

javascript - 从书签加载外部 JS?

javascript - Fabric js - 根据 Canvas 中添加的矩形调整整个 Canvas 的大小以实现裁剪

javascript - mongodb 的结果为 null,但 if (!result) 未捕获它

.net - WCF托管在Windows服务+网页中?

PHP Mail - 发现多个或格式错误的换行符