在localhost上service-worker.js
加载并运行正常,但在实时服务器上它没有加载,我在控制台中收到此错误:
The script has an unsupported MIME type ('text/x-js').
Failed to load resource: net::ERR_INSECURE_RESPONSE
Uncaught (in promise) DOMException: Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/x-js').
从http到https的重定向带有.htaccess
,如下所示:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
但最后我无法理解这一点。
有什么想法吗?
答案 0 :(得分:0)
您的实时服务器应返回HTTP响应标头content-type
,其值为" application / javascript"。相反,它会返回" text / x-js"。理想情况下,也应该支持UTF8。尝试将这些行添加到.htaccess
以更正所有* .js URI的MIME类型:
AddType application/javascript .js
AddCharset utf-8 .js
检查Chrome DevTools中的HTTP响应标头,以确保在您请求service-worker.js URL时服务器以标头content-type: text/javascript; charset=utf-8
响应