当前位置:网站首页>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
边栏推荐
- 开源一夏 | 阿里云物联网平台之极速体验
- 《安富莱嵌入式周报》第276期:2022.07.25--2022.07.31
- Neural networks, cool?
- 如何选择合适的损失函数,请看......
- 方舟开服工具、服务器教程win
- Basic knowledge points in js - events
- How much does Ark Survival Evolved cost?
- ReentrantLock详解
- Introduction to the advantages of the new generation mesh network protocol T-Mesh wireless communication technology
- 基于牛顿方法在直流微电网潮流研究(Matlab代码实现)
猜你喜欢
JS basics--judgment
[微信小程序开发者工具] × #initialize
AI也有健忘症?英国41岁教授专访:解决灾难性遗忘
用友YonSuite与旺店通数据集成对接-技术篇2
Internship Road: Documenting Confusion in My First Internship Project
【899. Ordered Queue】
Interpretation of the 2021 Cost of Data Breach Report
出海季,互联网出海锦囊之本地化
【Unity入门计划】基本概念(6)-精灵渲染器 Sprite Renderer
深度学习GPU最全对比,到底谁才是性价比之王?
随机推荐
【Unity入门计划】基本概念(8)-瓦片地图 TileMap 02
[Code Hoof Set Novice Village 600 Questions] Define a function as a macro
30W 2C(JD6606S + FP6652X2)BOM
【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例
ModelWhale 云端运行 WRF 中尺度数值气象模式,随时随地即开即用的一体化工作流
请问大家,MySQL全量怎么样可以提高性能呢?我这里瓶颈是在Source上,在不增加并行度的情况下,
JS基础--判断
扫雷?拿来吧你(递归展开+坐标标记)
深入浅出Flask PIN
常见分布式理论(CAP、BASE)和一致性协议(Gosssip、Raft)
Reptile attention
高可用版 主数据库数据结构改变 备数据库会自动改变吗
无内鬼,来点干货!SQL优化和诊断
一文看懂推荐系统:概要02:推荐系统的链路,从召回粗排,到精排,到重排,最终推荐展示给用户
为教育插上数字化的翅膀,网易云信发布「互联网+教育」整体解决方案
window.open不显示favicon.icon
基于DMS的数仓智能运维服务,知多少?
Go Go 简单的很,标准库之 fmt 包的一键入门
方舟开服工具、服务器教程win
Ark server open tool, server tutorial win