Bobcares

How to Exclude URL in LiteSpeed Cache?

by | Nov 11, 2024

Exclude URL within LiteSpeed Cache allows us to exclude specific URLs (or patterns of URLs) from being cached. In this article, we’ll see the details of Exclude URL functionality. As part of our Server Management Service, Bobcares provides answers to all of your questions.

Overview
  1. How We Optimize Dynamic Content with URL Exclusions in LiteSpeed Cache?
  2. Why Exclude URLs?
  3. How to Exclude URLs in LiteSpeed Cache?
  4. Manually Excluding URLs (Advanced Users)
  5. Using Wildcards and Regular Expressions
  6. Common Use Cases for URL Exclusions
  7. Testing URL Exclusions
  8. Best Practices for URL Exclusion
  9. Conclusion

How We Optimize Dynamic Content with URL Exclusions in LiteSpeed Cache?

The LiteSpeed Cache plugin offers a powerful “Exclude URL” feature, allowing us to prevent specific URLs (or URL patterns) from being cached. This feature is essential for pages that display dynamic or user-specific content, ensuring they always load fresh rather than from cache. Below, we’ll explore why we might want to exclude URLs, how to do it, and the best practices for effective cache management.

litespeed cache exclude url

Why Exclude URLs?

Certain pages on the site benefit from not being cached. Here’s why:

  • Dynamic Content: Pages with constantly updating information, like shopping carts or account pages, need fresh data to ensure users see accurate information.
  • User-Specific Data: Pages with personalized content (e.g., user dashboards, offers) should not be cached to prevent showing the wrong data to the wrong user.
  • Form Submission: For pages with forms, excluding caching prevents issues with real-time validation and avoids showing stale data.
  • Search or Query Results: Search result pages should reflect the latest data to improve user experience, so caching is not ideal.

How to Exclude URLs in LiteSpeed Cache?

Setting up URL exclusions is simple and can be done through the LiteSpeed Cache plugin interface or manually for more advanced setups.

For WordPress Users (Using LiteSpeed Cache Plugin)

1. Navigate to LiteSpeed Cache → Settings in the WordPress dashboard.

2. Click on the Cache tab.

3. Scroll to the “Excludes” section to find the exclusion options.

4. In Do Not Cache URIs, specify URLs or patterns we want to exclude.

5. Use relative paths (like /my-account/, /checkout/) or patterns with wildcards to target multiple pages.

Examples:

Exclude a single page: /checkout/

Exclude pages with a pattern: /user/* (excludes /user/profile, /user/settings, etc.)

6. Once the exclusions are set, click Save Changes to apply.

Manually Excluding URLs (Advanced Users)

For custom setups, exclusions can be configured via .htaccess with LiteSpeed Cache directives:

RewriteCond %{REQUEST_URI} ^/checkout/ [OR]
RewriteCond %{REQUEST_URI} ^/cart/
RewriteRule .* - [E=Cache-Control:no-cache]

This example excludes the /checkout/ and /cart/ pages, ensuring they always load fresh.

Using Wildcards and Regular Expressions

LiteSpeed Cache supports wildcards for URL patterns, allowing us to exclude multiple pages without listing each one individually.

  • Wildcard Example: To exclude all product pages, use /product/*. This pattern excludes URLs like /product/shoes, /product/tshirts, and so on.
  • Regular Expressions: Advanced users can use regex for complex exclusion patterns, enabling more precise control.

Common Use Cases for URL Exclusions

To maintain a smooth, user-specific experience, here are some common cases where URL exclusions are best:

1. E-commerce Pages:

Avoid caching for checkout, cart, and payment pages, which contain user-specific data.

Example: Exclude /checkout/, /cart/, /my-account/.

2. User Dashboards:

For sites with user logins, exclude URLs associated with user profiles to secure personal data.

Example: Exclude /user/*, /profile/*.

3. Form Submission Pages:

Exclude pages with forms, especially if they use AJAX for real-time feedback.

Example: Exclude /contact/, /apply-form/.

4. Search Results Pages:

Prevent caching on search or filter pages to always show updated results.

Example: Exclude /search/.

5. Admin or Backend Pages:

For security, exclude backend or admin areas from caching.

Example: Exclude /wp-admin/, /admin/.

Testing URL Exclusions

Once setting up exclusions, we need to confirm they’re working correctly.

1. Use the browser’s developer tools (F12) to view HTTP response headers for the excluded pages.

2. If excluded, we won’t see “X-LiteSpeed-Cache: hit” but rather “X-LiteSpeed-Cache: miss” or nothing at all.

3. Clear the cache from the plugin dashboard or control panel, then reload excluded pages to verify they’re not cached.

Best Practices for URL Exclusion

1. Use Specific Patterns: Avoid broad exclusions (like entire directories) unless necessary. Keep exclusions as specific as possible to optimize cache performance.

2. Regular Testing: Test the performance of excluded URLs regularly to ensure they’re functioning correctly and aren’t cached.

3. Monitor Resource Usage: Excluding too many pages could impact server performance, especially on high-traffic sites. For these, consider shorter cache durations or other optimizations.

[Need to know more? Click here to reach us.]

Conclusion

In conclusion, LiteSpeed Cache’s URL Exclusion feature is a valuable tool to optimize dynamic content and user-specific data. By carefully choosing the pages to exclude, we can deliver a seamless, updated experience for users without sacrificing the performance benefits of caching.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF