我曾经sw-precache
为Firebase
托管的 Angular 2 应用程序生成服务工作者。
错误:
Service Worker registration failed: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.
结构
src-
app--
index.html
service-worker.js
sw-precache-config.js
sw-precache-config.js
module.exports = {
navigateFallback: '../index.html',
stripPrefix: 'dist',
root: 'dist/',
staticFileGlobs: [
'dist/index.html',
'dist/**.js',
'dist/**.css'
]
};
索引.html
<script>
if ('serviceWorker' in navigator) {
console.log(navigator.serviceWorker);
navigator.serviceWorker.register('service-worker.js').then(function (registration) {
console.log('Service Worker registered');
}).catch(function (err) {
console.log('Service Worker registration failed: ', err);
});
}
</script>