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.');
}
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.
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.
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:
And check the content:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With