diff --git a/.eslintignore b/.eslintignore index 49a3b042518..eadb6ce7c2a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,5 +2,4 @@ **/node_modules/** **/vendor/** **/assets/js/*.js -!assets/js/amp-service-worker-runtime-precaching.js build/* diff --git a/.gitignore b/.gitignore index 02c5500f509..6ffad39573d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ node_modules !/assets/css/src/ /assets/js/**/*.js /assets/js/*.asset.php -!/assets/js/amp-service-worker-runtime-precaching.js /assets/js/*.map /built /amphtml diff --git a/Gruntfile.js b/Gruntfile.js index 17cb8192074..fb1b9a40711 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -53,7 +53,6 @@ module.exports = function (grunt) { src: [ 'assets/js/**/*.js', 'assets/js/**/*.js.map', - '!assets/js/amp-service-worker-runtime-precaching.js', 'assets/js/**/*.asset.php', 'assets/css/*.css', 'assets/css/*.css.map', diff --git a/assets/js/amp-service-worker-runtime-precaching.js b/assets/js/amp-service-worker-runtime-precaching.js deleted file mode 100644 index 0ad59f81e6d..00000000000 --- a/assets/js/amp-service-worker-runtime-precaching.js +++ /dev/null @@ -1,11 +0,0 @@ -/* global URLS */ -// See AMP_Service_Workers::add_amp_runtime_caching() and . -{ - self.addEventListener('install', (event) => { - event.waitUntil( - caches - .open(wp.serviceWorker.core.cacheNames.runtime) - .then((cache) => cache.addAll(URLS)) - ); - }); -} diff --git a/includes/class-amp-service-worker.php b/includes/class-amp-service-worker.php index 624e097c1bb..f8eeb9e2886 100644 --- a/includes/class-amp-service-worker.php +++ b/includes/class-amp-service-worker.php @@ -111,26 +111,6 @@ public static function add_cdn_script_caching( $service_workers ) { return; } - // Add AMP scripts to runtime cache which will then get stale-while-revalidate strategy. - $service_workers->register( - 'amp-cdn-runtime-caching', - static function() { - $urls = AMP_Service_Worker::get_precached_script_cdn_urls(); - if ( empty( $urls ) ) { - return ''; - } - - $js = file_get_contents( AMP__DIR__ . '/assets/js/amp-service-worker-runtime-precaching.js' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents, WordPress.WP.AlternativeFunctions.file_system_read_file_get_contents - $js = preg_replace( '#/\*\s*global.+?\*/#', '', $js ); - $js = str_replace( - 'URLS', - wp_json_encode( $urls ), - $js - ); - return $js; - } - ); - // Serve the AMP Runtime from cache and check for an updated version in the background. See . self::register_caching_route( $service_workers, diff --git a/tests/php/test-class-amp-service-worker.php b/tests/php/test-class-amp-service-worker.php index a70c57818b7..94e8bb1aa71 100644 --- a/tests/php/test-class-amp-service-worker.php +++ b/tests/php/test-class-amp-service-worker.php @@ -88,16 +88,6 @@ public function test_add_query_var() { $this->assertIsString( $query_vars[1] ); } - /** - * Test add_cdn_script_caching(). - * - * @covers \AMP_Service_Worker::add_cdn_script_caching() - */ - public function test_add_cdn_script_caching() { - AMP_Service_Worker::add_cdn_script_caching( wp_service_workers()->get_registry() ); - $this->assertArrayHasKey( 'amp-cdn-runtime-caching', wp_service_workers()->get_registry()->registered ); - } - /** * Test add_image_caching(). *