2

When on localhost the service-worker.js loads and works just fine, but on the live server it's not loading and I get this error in the console:

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').

There is a redirect from http to https with a .htaccess which looks like this:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  • I know this has been asked before, but not fully answered.
  • I know it might have something to do with the .htaccess file like mentioned here.
  • It could also have something to do with the vue.js framework pointed out here

But in the end I can't get my head around this.

Any ideas?

1 Answers1

1

Your live server should return HTTP response header content-type with a value of "application/javascript". Instead it's returning "text/x-js". Ideally, UTF8 should be also be supported. Try adding these lines to .htaccess to correct the MIME type for all *.js URIs:

AddType application/javascript .js 
AddCharset utf-8 .js 

Inspect the HTTP response headers in Chrome DevTools to ensure that the server responds with header content-type: text/javascript; charset=utf-8 when you request your service-worker.js URL

anthumchris
  • 8,245
  • 2
  • 28
  • 53