Differences

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

Link to this comparison view

Next revision
Previous revision
litespeed_wiki:cache:lscwp:understanding_cookies [2018/07/20 16:17]
Lisa Clarke created
litespeed_wiki:cache:lscwp:understanding_cookies [2020/11/14 15:44] (current)
Lisa Clarke Redirect to new Documentation Site
Line 1: Line 1:
-====== Understanding Cookies in LiteSpeed Cache for WordPress ====== +~~REDIRECT>https://docs.litespeedtech.com/lscache/lscwp/admin/~~
-The relationship between cookies and caching can be easily misunderstood. When you talk about "​caching cookies"​ or "not caching cookies,"​ it's not the //cookies themselves//​ that are being cached or not cached. It's the //pages of the site// that are being cached or not cached based on whether a user has those cookies stored. Cookies, generally, are ignored unless you specify otherwise. +
- +
-Cookies become important when they effect the user experience in some way.  +
- +
-===== Cookies Set or Read by WordPress ===== +
-If a cookie must be //set or read by WordPress//,​ then it has to be excluded from cache. +
-And, if the cookies are set on your site (i.e. they are not set somewhere before arriving at your site), then you will //also// have to exclude the page that sets the cookie'​s value. +
- +
-==== Example ==== +
-Your site is part of an affiliate network. When a user arrives at ''<​nowiki>example.com/​afilliate_home</​nowiki>''​ an ''​aff-example''​ cookie is set. As they navigate the site, the cookie is updated with tracking information. +
- +
-In this case, the cookie ''​aff-example''​ must be added to the **Do Not Cache Cookies** list in **Settings > Excludes**, and ''​^/​afilliate_home''​ must be added to **Do Not Cache URIs** list on the same page. (For more on the **Excludes** page, see [[litespeed//​wiki:cache:​lscwp:​configuration:​excludes|the LSCWP Excludes Settings wiki]].) +
- +
-If, in this example, the cookie was set at ''<​nowiki>​example.com/afilliate_home<​/nowiki>'',​ but then never referenced again, you would not have to exclude the cookie from cache. +
- +
-Alternately,​ if the cookie was set offsite somewhere, but was used for tracking as the visitor wandered around your site, then you //would// have to exclude the cookie from cache, but you //​wouldn'​t//​ have to exclude the ''​^/​afilliate_home''​ URI. +
- +
-===== Cookies That Indicate Variations ===== +
-Sometimes cookies can be used to indicate important information about the user to WordPress, to help determine what content should be shown to the user. In these cases, you can use the cookies to create cache varies. When LSCache varies on a cookie, it caches separate public versions of the pages of the site, based on the value of the cookie.  +
- +
-==== Example ==== +
-Your WP site is a shop, and you have special pricing for your friends that is activated when they visit ''<​nowiki>​example.com/friends_home<​/nowiki>''​. That page sets a ''​myfriend''​ cookie, and from that point on, every page they visit in your shop shows pricing that is 20% less than normal. When a visitor without the ''​myfriend''​ cookie looks at the pages in your shop, they see regular prices. +
- +
-Because the cookie is set on the ''<​nowiki>​example.com/friends_home<​/nowiki>''​ page, that URI will need to be excluded from cache as described above. +
- +
-There are two ways to deal with the cookie itself: +
-  * You could do as the previous example, and exclude it from cache. That's the easiest way, but it means your friends will always have uncached content, and that's not an ideal experience for them. +
-  * You could create a cache vary based on the ''​myfriend''​ cookie. This creates two separate variations in cache for every page: one for people with the ''​myfriend''​ cookie, and one for people without it. This option is slightly more advanced, as it requires you to edit your ''​.htaccess''​ file, [[litespeed_wiki:​cache:​common:​views-based-on-cookie-values|like so]]. +
- +
-===== Further Reading ===== +
-You can learn more about cookies and cache varies in our [[litespeed_wiki:​cache:​developer_guide:​cache-vary|Developer'​s Guide to Cache Vary]]. ​+
  • Admin
  • Last modified: 2018/07/20 16:17
  • by Lisa Clarke