Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
litespeed_wiki:cache:no-plugin-advanced:esi-support [2019/01/24 17:11]
Lisa Clarke Copyediting
litespeed_wiki:cache:no-plugin-advanced:esi-support [2019/01/24 17:29]
Lisa Clarke Folded Cache Control Response Header into Enabling ESI
Line 50: Line 50:
 Enables the usage of ESI variables (listed [[https://​www.w3.org/​TR/​esi-lang|at w3.org]]) Enables the usage of ESI variables (listed [[https://​www.w3.org/​TR/​esi-lang|at w3.org]])
  
-===== Cache Control Response Header ​===== +===== Enabling ESI Support ​=====
-In addition to the ESI tags, the ''​X-LiteSpeed-Cache-Control''​ response header needs to include ''​esi=on'',​ or this can also be done by using a rewrite rule to enable ESI.+
  
-This notifies the server to parse the response ​for ESI tags. Upon finding an ESI tagthe server will use the attributes to search for a cache entry and if not found, make the ESI request. If the ''​no-vary''​ cache control attribute is set, the varies will not be used to locate or store in the cache. +The server ​needs to know when to parse for ESI tags in the response bodyThere are two ways to enable ​ESI, via rewrite rules and via response ​header
- +
-The ESI resource needs to set response ​headers in order to be cached correctly''​X-LiteSpeed-Cache-Control''​ needs to be set like a normal cache entry (i.e. ''​public''/''​private''/''​shared''/''​no-cache,​ max-age''​)+
  
 Multiple levels of ESI includes are permitted. The maximum number of levels is 10. Multiple levels of ESI includes are permitted. The maximum number of levels is 10.
- 
-===== Enabling ESI Support ===== 
- 
-The server needs to know when to parse for ESI tags in the response body. There are two ways to enable ESI, via rewrite rules and via response header. Rewrite rules can be used for broader requirements if many pages need to check for ESI. 
- 
-Response Headers can be used on a more narrow scope, on a page by page basis. 
  
 <​code>​ <​code>​
Line 74: Line 65:
 The above code in ''​.htaccess''​ is must-have code in order to activate cache, regardless of which method you use to enable ESI. The above code in ''​.htaccess''​ is must-have code in order to activate cache, regardless of which method you use to enable ESI.
  
-==== Rewrite Rule ====+==== Response Headers ​====
  
-  RewriteRule ​.[E=esi_on:1]+Response Headers can be used on a more narrow scope, on a page by page basisThe ''​X-LiteSpeed-Cache-Control''​ response header needs to include ''​esi=on''​.
  
-The above rewrite rule would activate ESI support ​for all pagesIf you only have ESI on a specific pageyou might want to only enable ESI for that page:+This notifies the server to parse the response ​for ESI tagsUpon finding an ESI tagthe server will use the attributes ​to search ​for a cache entry and if not found, make the ESI request. If the ''​no-vary''​ cache control attribute is set, the varies will not be used to locate or store in the cache.
  
-  RewriteRule PAGE_URI ​[E=esi_on:​1] +The ESI resource needs to set response headers in order to be cached correctly. ''​X-LiteSpeed-Cache-Control''​ needs to be set like a normal cache entry (i.e. ''​public''/''​private''/''​shared''/''​no-cache,​ max-age''​) 
-   + 
-==== HTTP Header ====  +
-  +
   <?php   <?php
   header('​X-LiteSpeed-Cache-Control:​ public, max-age=120,​ esi=on'​);​   header('​X-LiteSpeed-Cache-Control:​ public, max-age=120,​ esi=on'​);​
Line 90: Line 79:
   ...   ...
   ?>   ?>
-  ​+ 
 +==== Rewrite Rules ==== 
 + 
 +Rewrite rules can be used for broader requirements if many pages need to check for ESI. 
 + 
 +  RewriteRule .? - [E=esi_on:​1] 
 + 
 +The above rewrite rule would activate ESI support for all pages. If you only have ESI on a specific page, you might want to only enable ESI for that page: 
 + 
 +  RewriteRule PAGE_URI - [E=esi_on:​1]  ​
  
 ===== Example ===== ===== Example =====
  • Admin
  • Last modified: 2020/12/10 14:36
  • by Lisa Clarke