当前位置:网站首页>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
边栏推荐
- 请问大家,MySQL全量怎么样可以提高性能呢?我这里瓶颈是在Source上,在不增加并行度的情况下,
- Js array method is summarized
- 红蓝对抗经验分享:CS免杀姿势
- Essentially a database data recovery 】 【 database cannot read data recovery case
- Yii2安装遇到Loading composer repositories with package information
- 爬虫注意
- devops-3:Jenkins增加静态节点
- 兔起鹘落全端涵盖,Go lang1.18入门精炼教程,由白丁入鸿儒,全平台(Sublime 4)Go lang开发环境搭建EP00
- ruoyi若依框架@DataScope注解使用以及碰到的一些问题
- 为什么我强烈推荐使用智能化async?
猜你喜欢
【899. Ordered Queue】
How to play deep paging with hundreds of millions of data?Compatible with MySQL + ES + MongoDB
基于牛顿方法在直流微电网潮流研究(Matlab代码实现)
Daily practice------There are 10 numbers that are required to be output from large to small by selection method
Optimal Power Flow (OPF) for High Voltage Direct Current (HVDC) (Matlab code implementation)
深度学习——安装CUDA以及CUDNN实现tensorflow的GPU运行
js中的基础知识点 —— 事件
How much does Ark Survival Evolved cost?
Interpretation of the 2021 Cost of Data Breach Report
美国国防部更“青睐”光量子系统研究路线
随机推荐
[微信小程序开发者工具] × #initialize
泰山OFFICE技术讲座:文字边框高度研究
参与便有奖,《新程序员》杂志福利来袭!
mysql delete execution error: You can't specify target table 'doctor_info' for update in FROM clause
袁小林:沃尔沃专注于出行的安全感,并且把它做到极致
自定SvgIcon公用组件
用户侧有什么办法可以自检hologres单表占用内存具体是元数据、计算、缓存的使用情况?
How to get the 2 d space prior to ViT?UMA & Hong Kong institute of technology & ali SP - ViT, study for visual Transformer 2 d space prior knowledge!.
I am doing open source in Didi
JS基础--判断
【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例
扫雷?拿来吧你(递归展开+坐标标记)
劲爆!协程终于来了!线程即将是过去式
CS免杀姿势
Basic knowledge points in js - events
5v充8.4v1A电流充电管理ic
证实了,百度没有快照了
5 v 8.4 v1A charging current charging management IC
出海季,互联网出海锦囊之本地化
深度学习——安装CUDA以及CUDNN实现tensorflow的GPU运行