SAP 电商云 Spartacus UI SSR 模式下发起的

2022-01-19  本文已影响0人  _扫地僧_

I create a storefront using Schematics based on version 3.4.5( which Razer is using ) and run it under SSR mode.

I access http://localhost:4000/ in browser.
Via Chrome dev tools I know that the source code of home page is generated by SSR server successfully.
However, even in SSR mode, I found the /cms/pages OCC API is still triggered from client side.



here is log in SSR server, no CSR fallback occurs.
However in client side, I do find these three OCC API calls.
Is this behavior working as designed?

I add the following code in app.module.ts:

ConfigModule.withConfig({
  state: {
    ssrTransfer: {
      keys: {
        products: true,
        cms: true
      }
    }
  }
});

and I observe the following OCC API calls in Chrome dev tools when I access home page returned by SSR server:

no API for product data are found.

So my understanding is:

the API for product data in client side is considered as "unnecessary calls to the back end for the state" and avoided by SSR transfer state, right?

也就是说,浏览器环境下的 Spartacus 应用不会再发起 product 请求。

For products - I guess the state was transferred from SSR to CSR.

结论

By default, Spartacus reloads CMS page data on every route change, regardless it has it already in ngrx state.

每次 Spartacus 发生 route change,即浏览器地址栏里的 url 发生变化时,都会重新加载 CMS page data.

However, customers can configure it differently via the Spartacus config routing.loadStrategy: RouteLoadStrategy.ONCE
It’s used in CmsPageGuard.shouldReload method.

客户可以通过修改 routing.loadStrategy 的值为 RouteLoadStrategy.ONCE 来更改这个行为。

更多Jerry的原创文章,尽在:"汪子熙":


上一篇下一篇

猜你喜欢

热点阅读