问题
Every thing is working fine at localhost but when i upload same file to live server i got below mentioned error.
Service Worker error : DOMException: Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html').
If anyone can point me in the right direction I'd greatly appreciate it! Thank you
回答1:
A Service Worker script has to be served using a JavaScript media type i.e. either of text/javascript
, application/javascript
or application/x-javascript
.
回答2:
It can be wrong path to your Service Worker.
回答3:
ServiceWorker supported MIME type are 'text/javascript', application/javascript and application/x-javascript. got to ur server file and set
response.writeHead(201, {
'Content-Type': 'application/javascript'
});
回答4:
Thanks for your time and efforts.I am finally able to solve the problem. The problem occur because i use .htaccess to modify my url. At modified url main.js is not able to load the sw.js.
来源:https://stackoverflow.com/questions/39241762/service-worker-error-not-working-on-livehttps-server