Service Worker error. Not working on live(https) server

夙愿已清 提交于 2019-12-08 05:47:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!