当前位置:网站首页>Some optional strategies and usage scenarios for PWA application Service Worker caching
Some optional strategies and usage scenarios for PWA application Service Worker caching
2022-08-03 16:06:00 【Wang Zixi】
SAP 电商云 Spartacus UI Provides the site as a PWA 运行的功能. This improves user performance,改善了用户体验,Because it adds another caching layer,And to reduce the server side rendering (SSR) 服务的负载.
PWA 的工作方式是,To define the application file list,It will be according to the content of the generated file hash. The hash for the browser on the client to determine whether the file has changed.Such as relocation cases,These files should be reloaded.
- Network only:Contents must always be the latest,Suitable for electricity payment and checkout,Balance statements such as scene.
- Network falling back to cache:The content of the priority to provide the latest. 但是,If a network failure or unstable,The contents of the can provide a little old.Applicable scenario has timely data,价格和费率(Need a disclaimer),订单状态等.
- Stale-while-revalidate:Can immediately provide caching content,But later should use update cache content.Applicable scenario has news feed,产品列表页面,留言等.
- Cache first, fall back to network:Content is the key,Can provide from the cache to improve performance,但 Service Worker Should be updated occasionally check.适用于 App shells 和 Common resources.
- Cache only: Applicable to the static content rarely change resources.
下面是 SAP 电商云 Spartacus UI ngsw-config.json 文件的内容:
{
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js",
"/manifest.webmanifest"
]
}
}
],
"dataGroups": [
{
"name": "basesites",
"urls": [
"*/basesites?fields=baseSites\\(uid,defaultLanguage\\(isocode\\),urlEncodingAttributes,urlPatterns,stores\\(currencies\\(isocode\\),defaultCurrency\\(isocode\\),languages\\(isocode\\),defaultLanguage\\(isocode\\)\\),theme,defaultPreviewCatalogId,defaultPreviewCategoryCode,defaultPreviewProductCode\\)*"
],
"cacheConfig": {
"maxSize": 1,
"maxAge": "1d",
"strategy": "performance"
}
}
]
}
ngsw-config.json 配置文件指定 Angular Service Worker Which files and data to cache URL,And it should be how to update the cache files and data.Angular CLI 在 ng build During reads the configuration file.
./node_modules/.bin/ngsw-config ./dist/<project-name> ./ngsw-config.json [/base/href]
该配置文件使用 JSON 格式. All the file path must be to / 开头,It corresponds to the deployment directory——通常是 CLI 项目中的 dist/<project-name>
.
Allow the special symbols in the file(通配符)的含义:
**
: 匹配 0 个或多个路径段*
: 匹配 0 个或多个字符,不包括 /?
: 只匹配一个字符,不包括 /!
:prefix The pattern is marked negative,This means that only contains files and pattern don't match
一些例子:
/**/*.html
: 匹配所有 HTML 文件/*.html
:匹配根目录下的 HTML 文件!/**/*.map
: 排除所有的 sourcemaps
边栏推荐
猜你喜欢
随机推荐
How to play deep paging with hundreds of millions of data?Compatible with MySQL + ES + MongoDB
CopyOnWriteArrayList详解
Ark server opening tutorial win
js中的基础知识点 —— 事件
How to start an NFT collection
window.open不显示favicon.icon
ffplay视频播放原理分析
出海季,互联网出海锦囊之本地化
DC-DC 2C (40W/30W) JD6606SX2 power back application
方舟开服教程win
请问下阿里云全托管flink能执行两条flink sql命令么?
深度学习——安装CUDA以及CUDNN实现tensorflow的GPU运行
字典表(还需要输入2个字)
No inner demons, to dry!SQL optimization and diagnosis
49 万奖金等你来拿!第四届实时计算 Flink 挑战赛启动,Beyond Stream Processing!
【Unity入门计划】基本概念(8)-瓦片地图 TileMap 02
生态剧变,电子签名SaaS模式迎来新突破,网络效应加速到来
ruoyi若依框架@DataScope注解使用以及碰到的一些问题
身为售后工程师的我还是觉得软件测试香,转行成功定薪11.5K,特来分享下经验。
Not to be ignored!Features and advantages of outdoor LED display