当前位置:网站首页>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
边栏推荐
猜你喜欢

30W 2C(JD6606S + FP6652X2)BOM

【码蹄集新手村600题】将一个函数定义宏

美国国防部更“青睐”光量子系统研究路线

【Unity入门计划】基本概念(6)-精灵渲染器 Sprite Renderer

【QT】Qt项目demo:数据在ui界面上显示,鼠标双击可弹窗显示具体信息

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

劲爆!协程终于来了!线程即将是过去式

一通骚操作,我把SQL执行效率提高了10000000倍!

A new round of competition for speech recognition has started. Will natural dialogue be the next commanding height?

方舟开服教程win
随机推荐
【码蹄集新手村600题】将一个函数定义宏
ECCV 2022 | 基于关系查询的时序动作检测方法
如何分析周活跃率?
一文看懂推荐系统:召回03:基于用户的协同过滤(UserCF),要计算用户之间的相似度
Windows服务器如何防止黑客入侵的安全设置
leetcode: 899. Ordered Queue [Thinking Question]
Optimal Power Flow (OPF) for High Voltage Direct Current (HVDC) (Matlab code implementation)
用户侧有什么办法可以自检hologres单表占用内存具体是元数据、计算、缓存的使用情况?
How to start an NFT collection
mysql delete 执行报错:You can‘t specify target table ‘doctor_info‘ for update in FROM clause
Deep Learning - Install CUDA and CUDNN to implement GPU operation of tensorflow
Neural networks, cool?
并发编程的核心问题
一文看懂推荐系统:概要02:推荐系统的链路,从召回粗排,到精排,到重排,最终推荐展示给用户
Internship Road: Documenting Confusion in My First Internship Project
How to play deep paging with hundreds of millions of data?Compatible with MySQL + ES + MongoDB
ModelWhale 云端运行 WRF 中尺度数值气象模式,随时随地即开即用的一体化工作流
【899. 有序队列】
5v充8.4v1A电流充电管理ic
美国国防部更“青睐”光量子系统研究路线