Troubleshooting WP Rocket Cache and Optimization Issues with Gravity Forms

Overview

This article explains how WP Rocket’s page caching and file optimization features can interfere with Gravity Forms, and how to identify and resolve the conflict.

WP Rocket combines page caching with JavaScript and CSS optimization. The page cache rarely breaks a public form on its own when the cache lifetime stays under the WordPress nonce window (12–24 hours; WP Rocket’s default is 10 hours). The optimization features on the File Optimization tab are the usual cause.

Symptoms

  • Conditional logic or other JavaScript-driven features don’t respond.
  • The whole form is missing on load. A form with conditional logic is printed with display:none and shown only after its init script runs.
  • Fields display incorrectly, or blank screens appear after submission with no styles on the confirmation.
  • Forms (including file uploads) fail to submit, showing “Your session has expired. Please refresh the page and try again.”
  • Save and Continue, Conversational Forms, Signature, or other add-on functionality behaves unexpectedly or breaks.
  • Forms work for logged-in users and fail for public visitors.
  • The same form and the same WP Rocket settings work on one site and fail on another.

Why It Happens

Delay JavaScript Execution

It holds scripts until the visitor interacts with the page. It doesn’t delay every script — WP Rocket’s automatic list already excludes Gravity Forms’ conditional logic and reCAPTCHA scripts — but if other Gravity Forms scripts are delayed while jQuery isn’t, conditional logic can fail to run. Fields built with JavaScript, such as date pickers, file uploads, signature fields, and rich text fields, also stay uninitialized until the visitor interacts with the page.

WP Rocket › File Optimization

Remove Unused CSS

It scans the page and keeps only the CSS used by what’s present in the loaded HTML. Elements that aren’t visible yet, like validation errors, the confirmation message, an open date picker, or an enhanced dropdown, can have their styles dropped as a result.

WP Rocket › File Optimization › Optimize CSS delivery

Minify, Combine, and Defer JavaScript

Minify JavaScript Files skips scripts that are already minified, which Gravity Forms’ scripts are. Combine JavaScript Files merges scripts into a single file and can change their execution order, though it’s turned off automatically while Delay JavaScript Execution is enabled. Load JavaScript Deferred can also change when scripts run relative to the rest of the page.

WP Rocket › File Optimization

Page Caching

It serves a saved copy of the page to logged-out visitors. Ajax and file upload submissions rely on a security token embedded in that page, so once the cached copy is old enough for the token to expire, submissions fail with “Your session has expired. Please refresh the page and try again.”

WP Rocket › Advanced Rules › Never Cache URL(s)

Note: WP Rocket periodically updates the lists of scripts it treats as compatible or incompatible with these features. Two sites with identical settings can behave differently if their lists are out of sync — use the Update Lists button on the Tools tab to refresh them.

Confirm the Issue

  1. Add ?nowprocket=1 to the end of the page URL and load it. This bypasses WP Rocket’s optimizations. If the form works there and not on the normal URL, WP Rocket is involved.
  2. Open the browser console and reload the form page. Any error naming a Gravity Forms function points to a script that failed to load in time.
  3. View the page source and search for rocketlazyloadscript. If it appears, Delay JavaScript Execution is active on this page.
  4. Search the source for wpr-usedcss. If it appears, Remove Unused CSS is active on this page.

How to Fix It

  1. Clear the cache and the Used CSS from the WP Rocket toolbar menu, then reload the form page.
  2. If conditional logic is broken, go to WP Rocket › File Optimization and add /gravityforms/ to Excluded JavaScript Files under Delay JavaScript Execution.
  3. If styling is missing, add the Gravity Forms stylesheets and the .gform_wrapper class to the CSS Safelist under Optimize CSS delivery, then clear the Used CSS again.
  4. If an Ajax-enabled form hangs or reloads, add the page to Never Cache URL(s) under WP Rocket › Advanced Rules.
  5. If the problem remains, turn off one File Optimization feature at a time, re-testing the form after each, rather than disabling the tab wholesale.

Resources