Hey, it’s possible to exclude dynamically generated inline JavaScript from being cached. Since this data is unique to each user and may change with every page load, here are a few approaches you can try:
- Exclude Specific Pages from Caching: If the inline JavaScript is only on specific pages, you can exclude those pages from caching. Here’s how:
- Go to WP-Optimize -> Cache -> Advanced Settings.
- In the “URLs to exclude from caching” section, add the specific page URLs or use wildcard patterns to match multiple pages (e.g.,
/members/*
).
- Use Cookies to Prevent Caching: If the dynamic content is user-specific and based on cookies, you can configure WP-Optimize to prevent caching when certain cookies are set. To do this:
- In the same Advanced Settings tab, scroll down to the “Cookies which, if present, will prevent caching” section.
- Add the cookie name (e.g.,
wordpress_logged_in*
for logged-in users) to the list. This will ensure that pages with those cookies present won’t be cached.
- Move Inline Script to an External File: Another approach is to move the inline JavaScript into an external file and load it asynchronously or using the
defer
attribute. This allows the script to run after the page has loaded, so it won’t be part of the cached content.
These steps should help prevent caching for the dynamic content on your site. Thank you!