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

Short-circuit Asset CDN in AMP responses #11374

Merged
merged 1 commit into from
Feb 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions modules/photon-cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public static function go() {
public static function cdnize_assets() {
global $wp_scripts, $wp_styles, $wp_version;

/*
* Short-circuit if AMP since not relevant as custom JS is not allowed and CSS is inlined.
* Note that it is not suitable to use the jetpack_force_disable_site_accelerator filter for this
* because it will be applied before the wp action, which is the point at which the queried object
* is available and we know whether the response will be AMP or not. This is particularly important
* for AMP-first (native AMP) pages where there are no AMP-specific URLs.
*/
if ( Jetpack_AMP_Support::is_amp_request() ) {
return;
}

/**
* Filters Jetpack CDN's Core version number and locale. Can be used to override the values
* that Jetpack uses to retrieve assets. Expects the values to be returned in an array.
Expand Down Expand Up @@ -92,6 +103,12 @@ public static function cdnize_assets() {
* @return string The expected relative path for the CDN-ed URL.
*/
public static function fix_script_relative_path( $relative, $src ) {

// Note relevant in AMP responses. See note above.
if ( Jetpack_AMP_Support::is_amp_request() ) {
return $relative;
}

$strpos = strpos( $src, '/wp-includes/' );

// We only treat URLs that have wp-includes in them. Cases like language textdomains
Expand Down