Skip to content

Commit

Permalink
Merge pull request #7895 from ampproject/fix/pwa-runtime-cache
Browse files Browse the repository at this point in the history
Eliminate runtime precaching of AMP scripts in Service Worker
  • Loading branch information
westonruter authored Nov 12, 2024
2 parents e2354ba + 871021e commit e9b7e61
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 44 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
**/node_modules/**
**/vendor/**
**/assets/js/*.js
!assets/js/amp-service-worker-runtime-precaching.js
build/*
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 0 additions & 11 deletions assets/js/amp-service-worker-runtime-precaching.js

This file was deleted.

20 changes: 0 additions & 20 deletions includes/class-amp-service-worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/ampproject/amp-by-example/blob/4593af61609898043302a101826ddafe7206bfd9/boilerplate-generator/templates/files/serviceworkerJs.js#L54-L58>.
self::register_caching_route(
$service_workers,
Expand Down
10 changes: 0 additions & 10 deletions tests/php/test-class-amp-service-worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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().
*
Expand Down

0 comments on commit e9b7e61

Please sign in to comment.