Support » Plugin: WP Fastest Cache » Exclude javascript variable from cache

  • Resolved smartynetwork

    (@smartynetwork)


    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 3 years, 4 months ago by smartynetwork.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude javascript variable from cache’ is closed to new replies.