当前位置:网站首页>关于 SAP 电商云 Spartacus UI Transfer State 冗余 API 请求发送的讨论
关于 SAP 电商云 Spartacus UI Transfer State 冗余 API 请求发送的讨论
2022-07-24 02:20:00 【汪子熙】
Angular 的 TransferState 类使服务器端渲染 (SSR) 和预渲染 (Prerendered-SSR) Angular 应用程序能够使用从服务器获取的数据并且有效地在浏览器中渲染。
如果您使用的是 SSR 或预渲染应用程序策略,那么该过程大致是这样的:
- 在服务器上预渲染或渲染应用程序
- 浏览器获取呈现的 HTML 和 CSS 并显示“静态”应用程序
- 浏览器获取、解析、解释和执行 JavaScript
- Angular 应用程序被引导,用新的“正在运行”的应用程序替换整个 DOM 树
- 应用程序已初始化,通常从远程服务器或 API 获取数据
- 用户与应用程序交互
这个场景有两个问题:
- DOM hydration 会重复替换整个节点树并重新绘制应用程序
- 应用程序会重复获取理论上已经读取过的数据,并由于 SSR 或预渲染站点策略而显示给用户
第一个问题是目前在 Angular 中没有解决的问题,但是,第二个问题已经有了解决方案,这就是本文论述的 Angular TransferState 机制。
Transfer State 是一种策略:
- 使用 SSR 或预渲染策略获取渲染完整“静态”应用程序所需的数据
- 序列化数据,并使用初始文档 (HTML) 响应发送数据
- 在应用程序初始化时,在运行时解析序列化数据,避免数据的冗余获取
从技术上讲,数据通过 JSON.stringify() 序列化并通过 JSON.parse() 解析。但是,通常我们不需要担心这一点,因为这是由 Angular 中的 TransferState 服务为我们执行的。
即使服务器在 SSR 模式下工作,在 Chrome 浏览器 network 里,仍然能观察到 CMS OCC API 的调用。



已经开启了 products 和 cms 的 ssrTransfer:
ConfigModule.withConfig({
state: {
ssrTransfer: {
keys: {
products: true,
cms: true
}
}
}
});

products:确实在客户端没有观察到 OCC API 调用去读取 product 数据。
cms:默认情况下,每次 route 发生变化时,Spartacus 都会重新加载 CMS 页面数据,不管它是否已经存在于 ngrx store 里。
客户可以通过修改配置项:Spartacus config routing.loadStrategy: RouteLoadStrategy.ONCE 来更改这个行为。
以上逻辑实现于 CmsPageGuard.shouldReload 方法里。
边栏推荐
- How to do a good job of accompanying translation
- Leetcode 70 climbing stairs, 199 right view of binary tree, 232 realizing queue with stack, 143 rearranging linked list
- Performance optimization of wechat applet (subcontracting, operation process details, simplified structure, native component communication)
- Redraw the button and make your own circular LED indicator
- Idea's gradle project Chinese garbled
- Qml- use listview to build a three-level treeview architecture
- Canvas drawing (mouse click to draw and lift to end)
- Small volume stock trading record | based on multi task crawler technology, realize level1 sampling of A-share real-time market
- [jailhouse article] virtualization over multiprocessor system on chip an enabling paradigm for
- Express operates mysql. What is wrong with the SQL?
猜你喜欢

Understand the transport layer protocol - tcp/udp

认识传输层协议—TCP/UDP

微信小程序之性能优化(分包、运行流程细节、精简结构、原生组件通信)

2022.7.22 JS entry common data types and methods

浅谈领域驱动设计
In depth understanding of the underlying framework of wechat applet (II) component system, exprser

Using tessellation in unity

毕业设计校园信息发布平台网站源码

分布式资源管理与任务调度框架Yarn

jmeter+influxdb+grafana压测实时监控平台搭建
随机推荐
Webshell management tool and its traffic characteristics analysis
响应式pbootcms模板装修设计类网站
5年接觸近百比特老板,身為獵頭的我,發現昇職的秘密不過4個字
Phpcms realizes product multi condition screening function
餐饮连锁门店重塑增长背后的数字化转型
Mysql database authorization learning
How CAD draws arrows with arcs
Understand the transport layer protocol - tcp/udp
Canvas drawing (mouse click to draw and lift to end)
J. Serval and essay (tarjan finds topological order)
Jar package used by jsonarray in main function provided by leetcode
Mysql database UDF authorization learning
NetCore-如何保证ICollection或List私有化不被外部修改?
View Binding 混淆问题。我两天都在研究混淆。
[C language] preprocessing details
Brief introduction of tfw6524 perfectly replacing imported pt6524 chip
Resumption: a deck of cards (54), three people fighting the landlord, what is the probability that the big and small kings are in the same family
Use of component El scrollbar
深入了解-微信开发者工具
Go基础笔记_5_数组切片