Support » Plugin: PWA » How can I tell the plugin to precache a set of pages (and no other pages)?

  • I see there are a few filters to adapt the caching behavior. But I don’t get how to use them appropriately.

    I want to pre-cache (i.e., without the user visiting the pages) a few pages. I don’t want a any other pages to be cached under no conditions (or, at least, I want to cache them with a lower exiry time).

    Is that possible?

Viewing 1 replies (of 1 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    Yes. For example, something like this should precache the given post, where the service worker will update it when it is modified (and after the service worker is then triggered to re-install):

    add_action( 'wp_front_service_worker', function( \WP_Service_Worker_Scripts $scripts ) {
    	$post_id = 123;
    	$scripts->precaching_routes()->register(
    		get_permalink( $post_id ),
    		array(
    			'revision' => get_post_modified_time( 'U', true, $post_id ),
    		)
    	);
    } )
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.