wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Detect when forms are used on a page and set its cache lifetime to 10 hours or less

Open jas8522 opened this issue 6 months ago • 0 comments

Is your feature request related to a problem? Please describe. When a form that uses a nonce (hopefully any form, like a contact form) exists on a page, currently there are only two solutions to ensure the nonce doesn't become invalidated:

  1. Set the entire site to 10 hours max cache lifetime, or
  2. Disable caching on the page with the form

One could also try to get the form's nonce timeframe increased, but most form plugins don't make this straightforward, so it's not a truly viable option.

This means if the cache lifetime is >10 hours there's a good chance forms will stop working intermittently, which is terrible for business and customer service. If that lifetime is >24 hours, it's even worse.

Yet this is quite inefficient when most pages on most sites could probably benefit from super-long cache times.

Describe the solution you'd like

WP-Rocket could automatically detect when forms are used on a page and automatically set that page's max lifetime to 10 hours.

Describe alternatives you've considered Alternatives are described above. None are as efficient as this request, in terms of usage of server resources and optimize performance for end-users while ensuring security remains as intended for the forms in question.

Additional context In a quick search here I found 2-3 other requests related to this issue, but none directly requesting this particular solution. Clearly others have experienced this issue. I'd bet many sites have encountered it without realizing that WP Rocket is essentially breaking their forms. This would be a great way to ensure forms continue working while keeping cache lfietimes optimized for the type of content on the pages in question.

jas8522 avatar Aug 25 '24 01:08 jas8522