Overview
This article explains how LiteSpeed Cache’s page caching and script optimization features can interfere with Gravity Forms, and how to identify and resolve the conflict.
LiteSpeed Cache’s default public cache lifetime is one week, long enough to outlive the security tokens inside an Ajax form or a file upload. Edge Side Includes (ESI), the feature that can refresh those tokens without leaving the page uncached, depends on which LiteSpeed server your host runs.
Symptoms
- Conditional logic or other JavaScript-driven features do nothing, with no error shown.
- Fields display incorrectly, or validation messages and the confirmation appear unstyled.
- The form fails to submit or shows a submission error.
- A blank screen appears after submission.
- Form data is not processed correctly.
- Save and Continue behaves unexpectedly.
- Conversational Forms or other add-on functionality breaks.
- File uploads return a 403 or a “session expired” message while the rest of the form works.
- The form works when you are logged in, but not for cached public visitors.
Note: The token failures below only appear once a page has been cached for a while. Purging the cache generates a new page with new security tokens, so the form works again immediately, but breaks again about a day later. If a form has been reported as intermittent, test on a page that has been sitting in the cache rather than one you just purged.
Why It Happens
Default Public Cache TTL
The default public cache lifetime is one week, while WordPress security tokens expire within 12–24 hours. A page cached for several days serves expired tokens, which breaks Ajax submissions, file uploads, and forms that require the visitor to be logged in.
LiteSpeed Cache › Cache › TTL › Default Public Cache TTL
Note: File upload fields use their own request and token, so they can fail with a 403 or a “session expired” message even when the rest of the form submits correctly.
JavaScript Defer and Delay
These options hold scripts back until the page has loaded or the visitor interacts with it. Gravity Forms scripts need to run for conditional logic, multi-page navigation, and submission, so holding them back can break those features.
LiteSpeed Cache › Page Optimization
Guest Mode
Guest Mode serves a cached copy of the page on a visitor’s first request, ignoring ESI, and loads the correct version afterward. The form in that first copy carries cached tokens.
LiteSpeed Cache › General › General Settings
Generate UCSS
Generate UCSS removes CSS rules it judges unused on the page. Styles for validation messages and the confirmation are not in the page HTML, so they can be removed.
LiteSpeed Cache › Page Optimization
Confirm the Issue
- Find Default Public Cache TTL under LiteSpeed Cache › Cache › TTL. The default is one week. If it is longer than a day, it can outlive the Ajax and file-upload tokens, and that is the first thing to address.
- Test on a page that has been cached for a while rather than one you have just purged. A freshly generated page will work regardless.
- Test in a private window as a first-time visitor. Guest Mode applies specifically to a visitor’s first request, so a second page load may behave differently from the first.
- If the problem is with styling or scripts rather than tokens, temporarily turn off one Page Optimization option at a time (JavaScript defer, JavaScript delay, Generate UCSS) and retest the form after each.
- If submissions seem to be going missing, open Forms › Entries and check the Spam view. The entry notes name the filter that flagged it.
How to Fix It
- Shorten the cache lifetime so cached pages expire before their security tokens do, or exclude your form pages from caching entirely. Excluding them is the most reliable option for pages whose sole purpose is to display a form. Both options are under LiteSpeed Cache › Cache.
- Exclude the Gravity Forms scripts and jQuery from any JavaScript optimization, such as defer, delay, or combine, and exclude the Gravity Forms styles from any CSS optimization, such as Generate UCSS. These settings are under LiteSpeed Cache › Page Optimization.
- Turn off Guest Mode and retest before concluding anything else is at fault.
- If you need to keep pages with forms cached, ESI can refresh those tokens on each request while the rest of the page stays cached. It depends on your LiteSpeed server, so check with your host whether it is available. As an alternative, the community add-on Fresh Forms for Gravity automatically excludes pages containing forms from supported caching solutions.
- Once you know which option is responsible, leave the others enabled, then purge the LiteSpeed cache and hard-refresh the page.
- If the problem persists, contact LiteSpeed support, or your host if they manage your LiteSpeed server, for help with the cache, optimization, and ESI configuration.
Resources
- FAQ on Cache and Script Optimizer Issues
- Troubleshooting Entries Marked as Spam
- LiteSpeed Cache General Settings
Disclaimer: Third-party services, plugins, or code snippets that are referenced by our Support documentation or in Support Team communications are provided as suggestions only. We do not evaluate, test or officially support third-party solutions. You are wholly responsible for determining if any suggestion given is sufficient to meet the functional, security, legal, ongoing cost and support needs of your project.
Feedback, feature, and integration requests, and other functionality ideas can be submitted at https://gravity.com/feature-request/.