当前位置:网站首页>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
边栏推荐
- 为教育插上数字化的翅膀,网易云信发布「互联网+教育」整体解决方案
- DC-DC 2C(40W/30W) JD6606SX2退功率应用
- 袁小林:沃尔沃专注于出行的安全感,并且把它做到极致
- 用友YonSuite与旺店通数据集成对接-技术篇2
- Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。
- 常见分布式理论(CAP、BASE)和一致性协议(Gosssip、Raft)
- 请问下,flink cdc监控oracle,我看源码是通过sid方式的,请问怎么改成service
- Ark server open tool, server tutorial win
- 6000 字+,帮你搞懂互联网架构演变历程!
- Ark server opening tutorial win
猜你喜欢

参与便有奖,《新程序员》杂志福利来袭!

技术干货|如何将 Pulsar 数据快速且无缝接入 Apache Doris

MySQL性能优化_小表驱动大表
![leetcode: 899. Ordered Queue [Thinking Question]](/img/e0/5ea1df0d40a166d0be0309b4608e6d.png)
leetcode: 899. Ordered Queue [Thinking Question]

【Unity入门计划】基本概念(8)-瓦片地图 TileMap 02

不可忽略!户外LED显示屏的特点及优势

Awesome!Coroutines are finally here!Thread is about to be in the past

Difference and performance comparison between HAL and LL library of STM32

一个文件管理系统的软硬件配置清单

nodeJs--跨域
随机推荐
聊聊这个SaaS领域爆火的话题
MySQL性能优化_小表驱动大表
How to start an NFT collection
Internship Road: Documenting Confusion in My First Internship Project
Go Go 简单的很,标准库之 fmt 包的一键入门
ruoyi若依框架@DataScope注解使用以及碰到的一些问题
参与便有奖,《新程序员》杂志福利来袭!
一个文件管理系统的软硬件配置清单
ffplay视频播放原理分析
JD6606SP5_JD6606SSP_JD6606SASP_JD6621W7百盛新纪元授权代理商
《安富莱嵌入式周报》第276期:2022.07.25--2022.07.31
A new round of competition for speech recognition has started. Will natural dialogue be the next commanding height?
AWS China SDN Connector
leetcode:899. 有序队列【思维题】
字典表(还需要输入2个字)
js数组方法总结
Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。
Basic knowledge points in js - events
[微信小程序开发者工具] × #initialize
美国国防部更“青睐”光量子系统研究路线