[康斯坦丁G供稿。]{class="badge informative" title="康斯坦丁G."}

清漆ESI區塊

Edge Side Include (ESI)是特殊指令,可用來將網頁包含在其他網頁中。

範例:

<div>
  <esi:include src="http://domain.com/index.php/page_cache/block/esi/blocks"/>
</div>

清漆從擷取內容 http://domain.com/index.php/page_cache/block/esi/blocks 並取代 <esi> 標籤之前是否有宣告。

Commerce and Varnish ESI

Commerce架構會在符合下列條件時建立ESI標籤:

  • 快取應用程式設定為 Varnish Cache
  • XML配置 block 元素新增了 ttl 屬性

範例

cms_index_index.xml:

  <referenceContainer name="content">
      <block class="Magento\Framework\View\Element\Template" template="Magento_Paypal::esi.phtml" ttl="30"/>
   </referenceContainer>

在上述範例中, block 元素新增以下專案的內容: esi.phtml 範本至首頁,Varnish每30秒會自動更新一次。

限制

目前Varnish不支援HTTPS上的ESI,因此會自動切換至HTTP。

Magento\PageCache\Observer\ProcessLayoutRenderElement:

    private function _wrapEsi(
        \Magento\Framework\View\Element\AbstractBlock $block,
        \Magento\Framework\View\Layout $layout
    ) {
    ....
        // Varnish does not support ESI over HTTPS must change to HTTP
        $url = substr($url, 0, 5) === 'https' ? 'http' . substr($url, 5) : $url;
        return sprintf('<esi:include src="%s" />', $url);
    }
recommendation-more-help
386822bd-e32c-40a8-81c2-ed90ad1e198c