【发布时间】:2019-06-04 22:55:18
【问题描述】:
我正在同时使用 Angular PWA 和 Angular Universal,我正在玩离线导航。
我试图为导航请求实现的行为是:
- 在线时,为服务器端呈现的页面提供最大的首次绘制速度(然后客户端接管)
- 离线时,回退到缓存的
index.html,以便使用缓存的客户端应用
问题在于ngsw-worker.js 及其配置文件ngsw-config.json 没有提供足够高的粒度级别来实现这一点。
这是我当前的ngsw-config.json,它提供了一种接近我想要实现的行为,但是当我在离线模式下刷新应用程序时,它仅在页面在在线模式下被刷新(因此被缓存)时才起作用之前。
{
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js"
]
}
},
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
],
"dataGroups": [
{
"name": "backend",
"urls": [
"/backend/**"
],
"cacheConfig": {
"maxSize": 100,
"maxAge": "3d",
"strategy": "freshness"
}
},
{
"name": "serverSideRenderedPages",
"urls": [
"/**"
],
"cacheConfig": {
"maxSize": 100,
"maxAge": "3d",
"strategy": "freshness"
}
}
],
"navigationUrls": [
"!/**"
]
}
我认为服务人员应该“具有普遍意识”,但如果不是,是否有任何干净的解决方案或解决方法?
【问题讨论】:
标签: angular progressive-web-apps angular-universal angular-pwa