Title: Exclude javascript variable from cache
Last modified: July 28, 2020

---

# Exclude javascript variable from cache

 *  Resolved [smartynetwork](https://wordpress.org/support/users/smartynetwork/)
 * (@smartynetwork)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-variable-from-cache/)
 * I store my WP Nonce in a javascript variable that is printed on the page like
   this:
 *     ```
       <script type='text/javascript'>
       /* <![CDATA[ */
       var THEME_VARS = {"ajaxurl":"https:\/\/example.com\/wp-admin\/admin-ajax.php","_nonce":"f0d72100e2","assets_url":"https:\/\/example.com\/wp-content\/themes\/themename\/assets","api_endpoint":"https:\/\/example.com\/wp-json\/wp\/v2\/"};
       /* ]]> */
       </script>
       ```
   
 * I use wp_localize_script() to print that. Then I can use `THEME_VARS._nonce` 
   in javascript files to send the nonce value with Ajax requests.
 * The problem is that since the javascript above is printed on the page, it is 
   also cached by WP Fastest Cache so when that page is served from cache the `_nonce`
   will have an old value and therefore the Ajax request will often fail after some
   time. Is there any way to exclude a certain portion of the page from cache? Or
   to exclude certain javascript variables?
    If no, then the plugin will be completely
   useless for my use case because it means I can’t use wp ajax in a reliable and
   secure way (unless I disable nonce check, which is a security feature). Any suggestion?
   I searched around but couldn’t find any documentation on that issue.
 * I can provide a demo link in private if you need to check.
    -  This topic was modified 5 years, 10 months ago by [smartynetwork](https://wordpress.org/support/users/smartynetwork/).

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

 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-variable-from-cache/#post-13182584)
 * it is not possible. please take a look at the following tutorial.
    [http://www.wpfastestcache.com/tutorial/wordpress-nonce-cache/](http://www.wpfastestcache.com/tutorial/wordpress-nonce-cache/)
 *  Thread Starter [smartynetwork](https://wordpress.org/support/users/smartynetwork/)
 * (@smartynetwork)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-variable-from-cache/#post-13184650)
 * Alright, I thought it’d be something like that but hoped for a more robust and
   permanent solution as i didn’t want to keep clearing cache very often because
   it’s a pretty big site. I added that and I’ll see how it performs.
    Thanks for
   the reply.
 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-variable-from-cache/#post-13184707)
 * I got you but there is no solution about it.

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

The topic ‘Exclude javascript variable from cache’ is closed to new replies.

 * ![](https://ps.w.org/wp-fastest-cache/assets/icon-256x256.png?rev=2064586)
 * [WP Fastest Cache - WordPress Cache Plugin](https://wordpress.org/plugins/wp-fastest-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-fastest-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-fastest-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-fastest-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-fastest-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-fastest-cache/reviews/)

## Tags

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

 * 3 replies
 * 2 participants
 * Last reply from: [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-variable-from-cache/#post-13184707)
 * Status: resolved