AWS Cloudfront 服务 javascript 个模块作为错误的 MIME 类型 ("Text/Plain")

AWS Cloudfront serving javascript modules as wrong MIME type( "Text/Plain")

我在 Amazon S3 存储桶上托管了一个 Vue 应用程序。当通过 S3 link w/http 访问时,它加载得很好。当我通过自定义 SSL 域 link 访问该站点到云端时,javascript 未正确提供服务。 JS 文件可以通过浏览器中的 https 完全访问,但不要在浏览器中执行,给我留下一个空白页面。 index.html 中的 javascript link 都出现以下错误:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.

另外:我按照这里的说明操作:https://levelup.gitconnected.com/deploying-vue-js-to-aws-with-https-and-a-custom-domain-name-3ae1f79fe188

明白了,我只需要在 S3 控制台中手动将各个 js 对象的系统定义内容类型从 text/plain 更改为 application/javascript,然后确保缓存已失效并在我的浏览器上刷新。

如果通过 aws 命令行工具上传,您可以使用正确的 mime/content 类型通过注册表编辑上传 javascript 文件。

修改注册表项

HKEY_CURRENT_USER\SOFTWARE\Classes.js

将“内容类型”设置为“application/javascript”

注意:上次 Windows 更新(截至 2022 年 1 月 14 日)悄悄将此注册表项恢复为“text/plain”。