如何防止 Angular service worker 缓存 PDF 文件?
How to prevent Angular service worker to cache PDF file?
我有一个带有 Service Worker 设置的 Angular 7 应用程序。但我刚刚注意到,当我尝试在我的网站上打开 PDF link 时,它们无法正常工作。
但是,如果我打开开发者控制台 > 应用程序并单击绕过网络它工作正常,如果我禁用服务工作者它也工作正常。
这是我的 ngsw-config.json
文件。
{
"index": "/index.html",
"assetGroups": [
{
"name": "app-shell",
"installMode": "prefetch",
"updateMode": "prefetch",
"resources": {
"files": [
"/index.html",
"/manifest.json",
"/ngsw-worker.js",
"/scripts*.js",
"/main*.js",
"/polyfills*.js",
"/runtime*.js",
"/common*.js",
"/*.css"
]
}
}, {
"name": "assets-lazy",
"installMode": "lazy",
"updateMode": "lazy",
"resources": {
"files": [
"/images/logo_red_white.svg",
"/logo.png",
"/assets/icons/**",
"/*.js"
]
}
}
]
}
当我查看开发人员工具上的网络选项卡时,我可以看到正在从服务工作者加载 PDF。
有什么方法可以让服务人员忽略 PDF 文件?
为什么不缓存 PDF 文件。这样,service-worker 就不会对 public 文件进行错误操作,并且您可以在页面上毫无问题地使用 PDF 文件。
要缓存 PDF 文件,请使用与存储或缓存图像相同的技术。
更多可以参考这个google link.
https://developers.google.com/web/ilt/pwa/lab-caching-files-with-service-worker
我有一个带有 Service Worker 设置的 Angular 7 应用程序。但我刚刚注意到,当我尝试在我的网站上打开 PDF link 时,它们无法正常工作。
但是,如果我打开开发者控制台 > 应用程序并单击绕过网络它工作正常,如果我禁用服务工作者它也工作正常。
这是我的 ngsw-config.json
文件。
{
"index": "/index.html",
"assetGroups": [
{
"name": "app-shell",
"installMode": "prefetch",
"updateMode": "prefetch",
"resources": {
"files": [
"/index.html",
"/manifest.json",
"/ngsw-worker.js",
"/scripts*.js",
"/main*.js",
"/polyfills*.js",
"/runtime*.js",
"/common*.js",
"/*.css"
]
}
}, {
"name": "assets-lazy",
"installMode": "lazy",
"updateMode": "lazy",
"resources": {
"files": [
"/images/logo_red_white.svg",
"/logo.png",
"/assets/icons/**",
"/*.js"
]
}
}
]
}
当我查看开发人员工具上的网络选项卡时,我可以看到正在从服务工作者加载 PDF。
有什么方法可以让服务人员忽略 PDF 文件?
为什么不缓存 PDF 文件。这样,service-worker 就不会对 public 文件进行错误操作,并且您可以在页面上毫无问题地使用 PDF 文件。 要缓存 PDF 文件,请使用与存储或缓存图像相同的技术。
更多可以参考这个google link.
https://developers.google.com/web/ilt/pwa/lab-caching-files-with-service-worker