I'm building a custom Rest Api endpoint. User can call this endpoint via ajax request in the frontend together with nonce value which was created by
wp_localize_script( 'some-js', 'wpApiSettings', [
'nonce' => wp_create_nonce( 'wp_rest' ),
],
] );
The problem is the caching plugin. In my case, I've used breeze.
It cache the page together with nonce value. When the nonce is expired, the page cache still have the expired nonce in it. So when the used this nonce, they receive rest_cookie_invalid_nonce
until the cached is cleared.
Is there a way to prevent this from happen?