Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision Last revision Both sides next revision | ||
litespeed_wiki:cache:lscwp:handle-cookie-vary [2018/10/08 15:01] Eric Leu created |
litespeed_wiki:cache:lscwp:handle-cookie-vary [2020/05/04 13:56] Shivam Saluja |
||
---|---|---|---|
Line 1: | Line 1: | ||
===== How to Configure Cookie Cache Vary ===== | ===== How to Configure Cookie Cache Vary ===== | ||
+ | **Please Note**: This wiki is valid for v2.9.x and below of the LiteSpeed Cache Plugin for WordPress. If you are using v3.0 or above, please see [[https://docs.litespeedtech.com/lscache/lscwp/overview/|the new documentation]]. | ||
- | Example: assume you have a woocommerce site and bring "woocommerce_products_per_page" cookie which should vary from user to user, and you should not serve everyone with the same cache file. | + | LiteSpeed Cache can be configured to save multiple variations of the same page, based on the value of a cookie in the user's browser. |
- | and there are two ways to accomplish this: a javascript-based plugin, and cache vary rewrite rules. | + | Example: Assume you have a WooCommerce site with a "woocommerce_products_per_page" cookie. For some users, the value will be ''10''. For others it will be ''100''. And still others may not have a value of ''200''. These three scenarios require three different views. |
- | The more efficient option is a javascript-based solution. A javascript plugin would only need to store one copy of the page and would build the display based on the existence of the cookie. If a rewrite rule-based answer is preferred, the site can be configured to vary on the cookie by adding the following rule to your site's .htaccess file: | + | There are two ways to accomplish this: |
+ | ====JavaScript-Based Plugin==== | ||
+ | |||
+ | The more efficient option is to find a JavaScript-based solution. A JavaScript plugin would only need to store one copy of the page and would build the display based on the existence of the cookie. | ||
+ | |||
+ | ====Cache Vary Rewrite Rules==== | ||
+ | If a rewrite rule-based answer is preferred, the site can be configured to vary on the cookie by adding the following rule to your site's .htaccess file: | ||
<IfModule LiteSpeed> | <IfModule LiteSpeed> | ||
Line 11: | Line 18: | ||
RewriteRule .* - [E=Cache-Vary:woocommerce_products_per_page] | RewriteRule .* - [E=Cache-Vary:woocommerce_products_per_page] | ||
</IfModule> | </IfModule> | ||
- | When user visit woocommerce site with ''woocommerce_products_per_page=xxxxxx''cookie will be created. Using the rewrite rule above, the cache will vary on that cookie. This means the cache will store two copies: one that shows the yellow bar at the bottom, and one that does not. | + | |
+ | When a user visit your WooCommerce site, the ''woocommerce_products_per_page=xxxxxx''cookie will be created. Using the rewrite rule above, the cache will vary on that cookie. This means the cache will store multiple copies: one for every value of the cookie that requests the page. | ||