Title: Exclude Inline JS from Cache
Last modified: September 28, 2024

---

# Exclude Inline JS from Cache

 *  Resolved [timtallop](https://wordpress.org/support/users/timtallop/)
 * (@timtallop)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/exclude-inline-js-from-cache/)
 * Hello,
 * Is it possible to exclude inline JS from page caching?
 * The data included in the inline script is dynamically generated (using a PHP 
   file) and is used by other JS files. It is unique to each user and can change
   with every page load.
 * Any input would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [wpmansour](https://wordpress.org/support/users/wpmansour/)
 * (@wpmansour)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/exclude-inline-js-from-cache/#post-18044048)
 * 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:
    1. **Exclude Specific Pages from Caching**: If the inline JavaScript is only on
       specific pages, you can exclude those pages from caching. Here’s how:
    2.  - 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/*`).
    3. **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:
    4.  - 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.
    5. **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!
 *  Thread Starter [timtallop](https://wordpress.org/support/users/timtallop/)
 * (@timtallop)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/exclude-inline-js-from-cache/#post-18044661)
 * Thank you very much for the thorough answer Mr. Mansour.
 * You have given me the idea to use cookies instead of inline JS for this use case,
   which would make it possible for the pages to get cached.
 *  [wpmansour](https://wordpress.org/support/users/wpmansour/)
 * (@wpmansour)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/exclude-inline-js-from-cache/#post-18044734)
 * You’re welcome! Glad to hear that : )

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Exclude Inline JS from Cache’ is closed to new replies.

 * ![](https://ps.w.org/wp-optimize/assets/icon-256x256.png?rev=1552899)
 * [WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance](https://wordpress.org/plugins/wp-optimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-optimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-optimize/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-optimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-optimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-optimize/reviews/)

## Tags

 * [cache](https://wordpress.org/support/topic-tag/cache/)
 * [caching](https://wordpress.org/support/topic-tag/caching/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 3 replies
 * 2 participants
 * Last reply from: [wpmansour](https://wordpress.org/support/users/wpmansour/)
 * Last activity: [1 year, 7 months ago](https://wordpress.org/support/topic/exclude-inline-js-from-cache/#post-18044734)
 * Status: resolved