Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active August 27, 2018 22:47
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/7b0705ae9ce8dcf3e1a8de28eb7b34b5 to your computer and use it in GitHub Desktop.
Save westonruter/7b0705ae9ce8dcf3e1a8de28eb7b34b5 to your computer and use it in GitHub Desktop.
<?php
/*
* Everything registered here will be concatenated into a single script that is
* served via /?wp_service_worker=1 which is installed as the service worker.
*/
add_action( 'wp_front_service_worker', function( WP_Service_Workers $sw ) {
$sw->register_script(
'static-file',
plugin_dir_url( __FILE__ ) . 'example.js',
array( 'main-site-id' ) // Dependency declared so this script will be output after the following.
);
$sw->register_script(
'main-site-id',
function() {
return sprintf( 'const mainSiteId = %s;', wp_json_encode( get_main_site_id() ) );
}
);
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment