Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMP scripts are added to runtime cache even if an AMP page is never accessed #7882

Open
westonruter opened this issue Sep 23, 2024 · 1 comment · May be fixed by #7895
Open

AMP scripts are added to runtime cache even if an AMP page is never accessed #7882

westonruter opened this issue Sep 23, 2024 · 1 comment · May be fixed by #7895
Labels
Bug Something isn't working Integration: PWA
Milestone

Comments

@westonruter
Copy link
Member

I just noticed when accessing a site in paired mode that the AMP scripts are being precached in the runtime cache even when not accessing an AMP page. This is due to the following logic:

// 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;
}
);

It should be removed.

@westonruter westonruter added Bug Something isn't working Integration: PWA labels Sep 23, 2024
@westonruter westonruter added this to the v2.5.5 milestone Sep 23, 2024
@westonruter
Copy link
Member Author

Alternatively, it should only be used on a site which is in Standard mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Integration: PWA
Projects
Status: To Do
Development

Successfully merging a pull request may close this issue.

1 participant