我有以下的sw-precache config.js
module.exports = {
staticFileGlobs: [
'index.html',
'manifest.json',
'bower_components/webcomponentsjs/*',
],
navigateFallback: 'index.html',
runtimeCaching: [{
urlPattern: /.+\/api\/.+/,
handler: 'networkOnly',
}],
};我有SPA应用程序与服务工作者(生成使用上述配置)来缓存资源。
当我在没有缓存资源的情况下打开myapp/api/ When (第一次访问网站)时,它工作得很好。
如果打开myapp的主页,浏览器会缓存资源和随后对myapp/api/ page的请求,会导致问题(生成myapp主页的布局,但没有数据)。
当我清除浏览器的缓存( tab Application - cache存储-清除)时,我可以再次打开myapp/api/ Cache。
因此,我的问题是:如何迫使浏览器忽略所有"myapp/api/*“路由的服务-worker.js?
发布于 2018-04-21 08:05:35
您只需要简单地忽略包含模式的请求。
// service-worker.js
self.onfetch = evt => {
let path = new URL(evt.request.url).pathname;
if(path.startsWith('/myapp/api')) {
// these requests will be networked
return;
}
// Handle other requests here
};https://stackoverflow.com/questions/49953487
复制相似问题