1

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

  • Load chrome://serviceworker-internals/ and check 'Open DevTools window and pause JavaScript execution on Service Worker startup for debugging.' – Vikrant Aug 31 '16 at 05:58
  • _“The script has an unsupported MIME type ('text/html')”_ – your server is not sending a correct Content-Type header for the script. – CBroe Aug 31 '16 at 07:20

4 Answers4

2

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.

dontcallmedom
  • 2,420
  • 14
  • 12
0

It can be wrong path to your Service Worker.

0

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'
});
WapShivam
  • 964
  • 12
  • 20
-2

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.

  • 1
    can you share your answer here? I got an error too `The script has an unsupported MIME type ('text/html').` – Jems Mar 20 '18 at 05:27