且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

注册 ServiceWorker 失败:脚本具有不受支持的 MIME 类型 ('text/html') Vue js?

更新时间:2022-02-01 02:56:04

我不确定,但是您可以尝试像这样注册 worker,以便我们可以获得有关进度的更多信息并正确设置路径:

I am not sure, but can you try to register the worker like this, so we can have additional information about the progress and set the path correctly:

...

navigator.serviceWorker
            .register("service-worker.js", {
    scope: './' }).then(function (registration) {
    var serviceWorker;
    if (registration.installing) {
        serviceWorker = registration.installing;
        console.log('installing');
    } else if (registration.waiting) {
        serviceWorker = registration.waiting;
        console.log('waiting');
    } else if (registration.active) {
        serviceWorker = registration.active;
        console.log('active');
    }
    if (serviceWorker) {
        // logState(serviceWorker.state);
        serviceWorker.addEventListener('statechange', function (e) {
            // logState(e.target.state);
        });
    }
}).catch({…})

你也可以展示一下

service-worker.js

service-worker.js

文件?