Last active
November 12, 2018 21:00
-
-
Save westonruter/f848013108672568be6dcde153f9ca37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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