这是我的吞咽任务:
gulp.task('service-worker', ['clean:sw'], function (cb) {
swPrecache.write(path.join(global.config.offlineRoot, 'sw.js'), {
staticFileGlobs: [
global.config.offlineRoot + '/offline/**/*.{js,html,css,png,jpg,jpeg,gif,svg,ttf,woff,woff2}',
global.config.offlineRoot + '/manifest.json'
],
dynamicUrlToDependencies: {
'/app-shell': ['lib/views/layouts/app-shell.hbs'],
'/': [
'lib/views/layouts/main-layout.hbs',
'lib/views/index.hbs'
]
},
runtimeCaching: [
{
// See https://github.com/GoogleChrome/sw-toolbox#methods
urlPattern: /^\/(?!login|admin)/,
handler: 'networkOnly'
}
],
stripPrefix: global.config.offlineRoot,
stripPrefixMulti: {
"node_modules/": 'scripts/'
},
navigateFallback: '/app-shell',
navigateFallbackWhitelist: [/^\/(?!login|admin)/],
cacheId: "nodebeats",
// importScripts: ['scripts/sw-toolbox/sw-toolbox.js'],
verbose: true,
maximumFileSizeToCacheInBytes: 3097152, //3mb
handleFetch: true//(global.config.env === 'prod')
})
.then(cb)
.catch(function () {
cb();
});
});
从上面的配置中,登录和管理路由仅使用网络获取,索引路由首先从缓存中提供,但我希望它首先是网络,因为我是从服务器端绑定我的页面。所以动态数据不会在应用程序中复制,除非 ctrl + f5