How to Resolve Issues Caused by Cache and Optimization Plugins
In This Document
Reading time: 4 minutes | Difficulty: Beginner
Overview
Caching plugins and web host caches make your site faster by saving a copy of each page and serving that copy to later visitors. Optimization plugins go further and minify, combine, or delay your site’s JavaScript. Both are good for performance, but they can interfere with payment forms if they are set up too aggressively.
Since WP Simple Pay 4.17.5, payment forms work on fully cached pages. Each form loads its settings and a fresh security token from your site as the page opens, so the cached copy of the page no longer holds anything that can expire. You don’t need to exclude your payment form pages from caching anymore.
This guide covers the two things that still need attention: keeping your payment confirmation pages out of the cache, and keeping WP Simple Pay’s scripts out of JavaScript optimizations.
Prerequisites
- WP Simple Pay 4.17.5 or later. On older versions, payment form pages must also be excluded from caching, or cached for no longer than 12 hours.
- Access to your caching or optimization plugin’s settings, or to your web host’s support team if the cache runs on the server.
Caching
Payment Form Pages
On WP Simple Pay 4.17.5 and later, pages that contain a payment form can be cached like any other page. When a visitor opens the page, each form fetches its own data from your site’s REST API. The payment button stays disabled until the form is ready, so an early click can’t submit an incomplete form.
If you excluded your payment form pages from caching on an earlier version, you can leave the exclusion in place or remove it. Both work.
Just updated? Clear your site’s cache once after updating to 4.17.5. Pages cached before the update still contain the old form code until they are refreshed.
Payment Confirmation Pages
Keep your payment success and failure pages excluded from caching. These pages show the details of a specific payment, so each customer must get a freshly generated page.
With some web hosts, the cache runs on the server and can’t be changed from WordPress. In that case, contact your host and ask them to exclude your confirmation page URLs from caching.
Configure Specific Plugins
- WP Rocket
- SiteGround Optimizer
- WP-Optimize
- WP Fastest Cache
- WP Super Cache
- W3 Total Cache
- LiteSpeed Cache
JavaScript Optimization
JavaScript issues caused by optimization plugins usually come from these features:
- Minify
Removes unnecessary characters from the code, such as white space, to produce a smaller file. - Combine
Merges separate JavaScript files into one to reduce the number of requests made to the server. - Load Deferred/Asynchronously
Delays loading or running JavaScript files so the page doesn’t wait for them.
Exclude the following files from every JavaScript optimization setting, whichever plugin you use:
js.stripe.com/v3/
simpay-public-shared.js
simpay-public-upe.js
accounting.min.js
simpay-public-pro-upe.js
What Optimization Must Leave in Place
Payment forms need a small set of site settings before they can load: your site’s REST API address, your currency format, and the message shown when a form can’t load. WP Simple Pay prints these settings in two places:
- Inside each payment form’s HTML, in the form’s
data-simpay-generalattribute. This copy is part of the form itself, so it is cached along with the page. - In a small script near the end of the page,
<script id="simpay-shared-js-extra">, which definesspGeneral.
Since WP Simple Pay 4.17.6, a form loads as long as either copy is on the page. Some optimization plugins remove or delay small inline scripts like the second one, and the form now uses its own copy when that happens.
To keep payment forms working, make sure your optimization plugin doesn’t:
- Remove HTML attributes from the payment form’s
<form>tag, especiallydata-simpay-form-idanddata-simpay-general. - Remove both the
data-simpay-generalattribute and thesimpay-shared-js-extrascript. If both are gone, the form can’t load.
Configure Specific Plugins
Troubleshooting
“This payment form could not be loaded”
If visitors see This payment form could not be loaded. Please refresh the page and try again. below the payment button, the form couldn’t fetch its data from your site. This is usually caused by something blocking your site’s REST API:
- A security or firewall plugin, or a server rule such as ModSecurity, is blocking requests to
/wp-json/. See How to Resolve the ‘No route was found matching the URL and request method’ Issue. - The visitor reached the request limit. See How to Manage the ‘Sorry, you have made too many requests’ Message.
- The payment form isn’t published. Forms only load on the front end when they are published.
Security Token Errors
Errors such as Coupon security check failed or Cookie nonce is invalid used to be caused by cached pages holding expired security tokens. Since 4.17.5, forms fetch a fresh token every time they load, and expired tokens on guest requests are recovered automatically. If you still see these errors after updating, clear your site’s cache. See How to Resolve the ‘Coupon security check failed’ Error for more.
Frequently Asked Questions
Do I still need to exclude payment form pages from caching?
No, not on WP Simple Pay 4.17.5 or later. You still need to exclude your payment confirmation pages.
I have custom code that reads window.spGeneral. Does it still work?
Yes. When the footer script is present, window.spGeneral is set by it, as before. When an optimization plugin has removed that script, WP Simple Pay sets window.spGeneral from the payment form’s data-simpay-general attribute as soon as its scripts load, so your code sees the same values.
I have custom code that reads window.simplePayForms. Does it still work?
Yes. The object is still available, and each form’s entry is added as that form’s data arrives. If your code runs as soon as the page loads, it may need to wait until the form has finished loading.
What’s Next?
- How to Configure WP Rocket Settings – Step-by-step settings for WP Rocket
- How to Set Payment Success and Failure Pages – Choose the pages customers land on after paying
- How to Test for Theme and Plugin Conflicts – Find out whether another plugin is causing the issue
Still have questions? We're here to help!
Last Modified: