-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to properly handle nonce caching? #237
Comments
That's a good question. What caching strategy are you using for pages? |
STRATEGY_STALE_WHILE_REVALIDATE add_filter(
'wp_service_worker_navigation_caching_strategy',
function() {
return WP_Service_Worker_Caching_Routes::STRATEGY_STALE_WHILE_REVALIDATE;
}
);
add_filter(
'wp_service_worker_navigation_caching_strategy_args',
function( $args ) {
$args['cacheName'] = 'pages';
$args['plugins']['expiration']['maxEntries'] = 20;
return $args;
}
); |
OK, thank you. Yes, I can definitely see how this would be problem. One possibility would be to make pages expire within the lifespan of the nonce. This can be done using add_filter(
'wp_service_worker_navigation_caching_strategy_args',
function( $args ) {
$args['cacheName'] = 'pages';
$args['plugins']['expiration']['maxEntries'] = 20;
// 👇 New!
/** This filter is documented in wp-includes/pluggable.php */
$max_age_seconds = apply_filters( 'nonce_life', DAY_IN_SECONDS );
$args['plugins']['expiration']['maxAgeSeconds'] = $max_age_seconds;
return $args;
}
); The value and applied filter there is copied from |
Brilliant, thanks! I'm going to give this a shot |
Thanks @westonruter ! That seemed to do it, no issues so far. Looking forward to the new plugin version! |
Added this guidance to the new wiki page: https://github.com/GoogleChromeLabs/pwa-wp/wiki/Service-Worker |
Hi,
I have a contact form that uses a nonce, when the nonce expires it stays in the cache unless page reload occurs. Since the nonce value is stale and no longer valid, it causes the form to fail. Is there a filter for specific nonce exclusion?
The text was updated successfully, but these errors were encountered: