If you’re using the LiteSpeed Cache (LSCache) plugin to optimize your WordPress website’s performance, you’ve probably noticed how effectively it improves loading times by caching content. However, there are times when you might want to exclude certain URIs from being cached to ensure that dynamic content or specific functionalities work correctly. In this guide, we’ll walk you through the process of how to exclude URIs in the WordPress LSCache plugin.
Why Exclude URIs from Caching?
Excluding URIs from caching can be necessary for several reasons:
- Dynamic Content: Pages that display dynamic content, such as shopping carts or forms, need to stay updated in real-time.
- Plugin Compatibility: Some plugins require their scripts or functionalities not to be cached to work correctly.
- User-Specific Data: Pages that show personalized data, like user dashboards, should not be cached to avoid displaying outdated or incorrect information.
Step-by-Step Guide on how to exclude URIs in WordPress LSCache plugin
Here’s how you can exclude specific URIs from being cached in the LSCache plugin:
1. Access LSCache Settings
- Log in to your WordPress dashboard.
- Navigate to LiteSpeed Cache > Cache.
- Click on the Excludes tab.
2. Locate the “Do Not Cache URIs” Section
In the Excludes settings, you’ll find various options to exclude caching for certain elements. Look for the “Do Not Cache URIs” section. This is where you can add the URIs that you want to exclude from caching.
3. Add URIs to Exclude
- Enter the specific URIs or patterns you want to exclude. You can add one URI per line.
- Example 1: If you want to exclude the contact page, add:
/contact
- Example 2: To exclude a custom plugin URL:
/wp-content/plugins/your-plugin-name/*
- Example 3: If you have a section that uses query strings and you want to exclude them, add:
/your-page/?nocache=true
4. Save and Purge the Cache
After adding the URIs, click Save Changes at the bottom of the page. Then, go to LiteSpeed Cache > Toolbox and click on Purge All to apply the changes immediately.
Excluding an Entire Plugin
In some cases, you may want to exclude an entire plugin from being cached. This is useful when a plugin relies on dynamic content or interacts with users in real-time, such as chat plugins, notification systems, or forms that must always show the latest data.
How to Exclude a Plugin
To exclude an entire plugin, identify the plugin’s directory path on the front end and add it to the “Do Not Cache URIs” section.
Example: If you want to exclude a plugin called “wordfence,” add:
wp-content/plugins/wordfence/*
This line tells LSCache to avoid caching any URL that includes the path to the “wordfence” plugin.
Best Practices for Excluding URIs
- Be Specific: Only exclude URIs that need to remain dynamic or require real-time updates. Overusing exclusions can impact the overall performance benefits of caching.
- Use Wildcards: If you need to exclude a range of URIs, you can use the
*
wildcard. For example,/shop/*
will exclude all pages under/shop/
. - Test After Excluding: After making changes, test the excluded pages to ensure they function correctly without any caching issues.
Common Use Cases for Excluding URIs
- E-commerce: Exclude shopping cart, checkout, and account pages.
- User-specific Pages: Exclude user profiles, dashboards, or areas showing personalized content.
- Third-party Plugins: Exclude plugins that handle dynamic content like forms, notifications, or real-time updates.
Troubleshooting Exclusions
If the exclusion doesn’t seem to work as expected:
- Check the URI Path: Make sure you’ve entered the correct path. It should start with a forward slash
/
and match the path in your website’s URL. - Clear the Cache: Always clear the entire cache after making changes to ensure they take effect.
- Disable Other Caching: Ensure other caching mechanisms, such as server-level caching, are not overriding your settings.
Conclusion
Excluding URIs or entire plugins in the WordPress LSCache plugin is an essential skill for maintaining the dynamic functionality of your site while still enjoying the benefits of caching. By carefully selecting which URIs to exclude, you can optimize your site’s performance without compromising its dynamic elements.
By following the steps outlined in this guide, you can easily manage cache exclusions and ensure that your WordPress site runs smoothly with LiteSpeed Cache.
Frequently Asked Questions (FAQs) Q1. Can I exclude multiple URIs at once?
Yes, you can exclude multiple URIs by entering each URI on a new line in the “Do Not Cache URIs” section.
Q2. How do I exclude a plugin from caching?
To exclude an entire plugin, identify the front-end URLs related to the plugin and use the pattern /wp-content/plugins/plugin-name/*
.
Q3. Does excluding URIs impact website speed?
Excluding URIs can impact the speed of those specific pages as they will no longer be served from the cache. However, it’s often necessary for pages with dynamic content to function correctly.
By understanding and implementing these exclusions, you can fine-tune how caching works on your website, ensuring that only the appropriate content is cached while dynamic content remains functional.