Cache Busting with Gravity Forms

View this code snippet on GitHub.


I think if there’s one thing everyone in the WordPress community agrees on, it’s this: caching is awesome. It improves the performance of your site and reduces the bandwidth required to load pages and files. WordPress-specific hosting providers typically cache pages by default, and if you’re managing your own server you can add any number of plugins, such as WP Super Cache, W3 Total Cache, and many more that can immediately improve page load times. If you aren’t taking advantage of caching on your site, you should.

If you use caching on your site, you should know that it can sometimes cause unexpected side effects with Gravity Forms. This can be further compounded when using our Perks, like Populate Anything, Nested Forms, and Limit Choices. To avoid this, it is recommended to bypass the cache on Gravity Forms with dynamic features.

One solution for this is to simply exclude those pages from the cache, but you lose the benefits of page caching. A better solution is to only bypass the cache for the form itself, and we cooked up a Cache Buster plugin to do just that.

It loads the form via AJAX (not to be confused with submitting the form via AJAX), bypassing the WordPress cache for the form only. This allows the page cache, and the performance boost that goes with it, to remain intact.

  1. Overview
  2. Using the Plugin
    1. Prerequisites
    2. Using the Shortcode
    3. Apply to All Forms
    4. Known Limitations
  3. Fresh Forms for Gravity

Using the Plugin


Confirm that you have Gravity Forms installed and activated and that you’ve installed and activated the plugin.

Using the Shortcode

When adding a form to a post or page via the [gravityforms] shortcode, simply add the “cachebuster” parameter:

[gravityforms id="123" cachebuster="1"]

The form will then load via AJAX , bypassing the WordPress cache.

Static forms that don’t use dynamic features are safe to leave cached!

Apply to All Forms

If you would rather apply the Cache Buster to every form on the page, you can do so by adding the following line to your theme’s functions.php file.

add_filter( 'gfcb_enable_cache_buster', '__return_true' );

The Cache Buster will now automatically apply to every form on your site.

Known Limitations

Cache Buster does not work with single File Upload fields due to browser security. It does work with Multi-file Upload fields since they upload via AJAX.

Fresh Forms for Gravity

Another solution for automatically bypassing the cache is Fresh Forms for Gravity. It supports most of the caching plugins out there and requires no setup. Simply install it and your forms will be excluded from the cache.

Leave a Comment

Your email address will not be published. Required fields are marked *