Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOMException: Failed to register a ServiceWorker: The script does not have a MIME type

It is my first time to use service worker. I got an error "The script does not have a MIME type.". Can anyone help with this issue?

The script does not have a MIME type.

Failed to load resource: net::ERR_INSECURE_RESPONSE

Service worker registration failed: DOMException: Failed to register a ServiceWorker: The script does not have a MIME type. register.js:6

register.js

// Make sure sw are supported
if ('serviceWorker' in navigator) {
    navigator.serviceWorker.register('sw_cached_page.js').then(function(registration) {
        console.log('Service Worker: Registered (Pages)');
    },function(error){
        console.log('Service worker registration failed:', error);
    });
}else{
    console.log('Service workers are not supported.');
}
like image 583
TYM Avatar asked Sep 19 '18 03:09

TYM


People also ask

What does unsupported MIME type mean?

However, it means that any requests for unknown text files initially get redirected to index. html , and therefore return with the MIME type of "text/html" , even if it's actually a JavaScript or SVG or some other kind of plaintext file.

How do I register a service worker in react?

In React, service workers are automatically added when you create your application through the create-react-app command, through SWPrecacheWebpackPlugin . Service workers ensure that the network is not a bottleneck to serve new requests.


1 Answers

This looks like your browser couldn't load the file sw_cached_page.js correctly. Check in chrome devtools what your browser actually downloaded.

Check the content-type:

Check the content-type

And check the content:

check the actual content

like image 156
Stef Chäser Avatar answered Oct 14 '22 10:10

Stef Chäser