Wordpress 仍然找不到硬编码的清单开始url?
我正在尝试将WordPress主题设置为渐进式Web应用程序。当我运行Chromes审计工具(lighthouse?)时,我得到了一个非信息性错误,我不知道到底是什么问题。错误是: 失败:服务工作者未成功为清单开始url提供服务。无法通过服务工作者获取开始url 我已经硬编码了我的起始url,这是一个有效的url。关于这个问题有什么建议吗Wordpress 仍然找不到硬编码的清单开始url?,wordpress,manifest,progressive-web-apps,Wordpress,Manifest,Progressive Web Apps,我正在尝试将WordPress主题设置为渐进式Web应用程序。当我运行Chromes审计工具(lighthouse?)时,我得到了一个非信息性错误,我不知道到底是什么问题。错误是: 失败:服务工作者未成功为清单开始url提供服务。无法通过服务工作者获取开始url 我已经硬编码了我的起始url,这是一个有效的url。关于这个问题有什么建议吗 https://mywebsite.com/wp-content/themes/mytheme/web.manifest: ... "scope":
https://mywebsite.com/wp-content/themes/mytheme/web.manifest
:
...
"scope": "/",
"start_url": "https://mywebsite.com",
"serviceworker": {
"src": "dist/assets/sw/service-worker.js",
"scope": "/aw/",
"update_via_cache": "none"
},
...
}
https://mywebsite.com/wp-content/themes/mytheme/dist/assets/sw/service-worker.js
:
...
// The fetch handler serves responses for same-origin resources from a cache.
// If no response is found, it populates the runtime cache with the response
// from the network before returning it to the page.
self.addEventListener('fetch', event => {
// Skip cross-origin requests, like those for Google Analytics.
if (event.request.url.startsWith(self.location.origin)) {
event.respondWith(
caches.match(event.request).then(cachedResponse => {
if (cachedResponse) {
return cachedResponse;
}
return caches.open(RUNTIME).then(cache => {
return fetch(event.request).then(response => {
// Put a copy of the response in the runtime cache.
return cache.put(event.request, response.clone()).then(() => {
return response;
});
});
});
})
);
}
});
我使用以下代码注册软件,并输出成功注册软件的信息:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(Vue.prototype.$ASSETS_PATH + 'sw/service-worker.js')
.then(function(registration) {
console.log('Registration successful, scope is:', registration.scope);
})
.catch(function(error) {
console.log('Service worker registration failed, error:', error);
});
}
请将您的起始url更改为
"start_url": "/"
它必须是一个相对的url。请看