Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active November 12, 2018 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/f848013108672568be6dcde153f9ca37 to your computer and use it in GitHub Desktop.
Save westonruter/f848013108672568be6dcde153f9ca37 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Stale While Revalidate
* Author: Weston Ruter
* Plugin URI: https://gist.github.com/westonruter/f848013108672568be6dcde153f9ca37
*/
// It is implied that the wp_service_worker_navigation_caching_strategy is for the front.
// @todo Instead of relying on filters, what if $scripts->navigation_routing->set_strategy( WP_Service_Worker_Caching_Routes::STRATEGY_STALE_WHILE_REVALIDATE )?
// @todo This could similarly be done to set navigation_preload, skip_waiting, clients_claim, etc.
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'] = 50;
$args['plugins']['expiration']['purgeOnQuotaError'] = true;
return $args;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment