-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add caching of redirect to non-AMP URL when validation errors present #1207
Conversation
9053ca8
to
a0c0859
Compare
includes/class-amp-theme-support.php
Outdated
$response = esc_html__( 'Redirecting to non-AMP version.', 'amp' ); | ||
|
||
if ( $cache_response ) { | ||
$cache_response( $response, $validation_results, $ampless_url ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think $ampless_url
should be cached here, but rather a flag for whether to redirect to the non-AMP URL. The URL should be computed at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
Hi @westonruter,
This looks good, and it's nice how it caches in case of a redirect due to blocking errors.
includes/class-amp-theme-support.php
Outdated
@@ -1732,12 +1756,18 @@ public static function prepare_response( $response, $args = array() ) { | |||
); | |||
} | |||
|
|||
$response = esc_html__( 'Redirecting to non-AMP version.', 'amp' ); | |||
|
|||
if ( $cache_response ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea to cache the response when there are blocking errors and it has to redirect to a non-AMP URL.
@kienstra I just made some additional changes to harden this. Note that to test you have to make sure that your
As opposed to:
|
79d2d13
to
f4f6604
Compare
@@ -1613,12 +1613,16 @@ public static function prepare_response( $response, $args = array() ) { | |||
&& | |||
! AMP_Validation_Manager::should_validate_response() | |||
), | |||
'user_can_validate' => AMP_Validation_Manager::has_cap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this is used to vary the cache.
Server-Timing Values Not Present, As Expected Hi @westonruter, Like you mentioned, before this PR, there were |
Moving To "Ready For Merging" If it's alright, I'm moving this to "Ready For Merging." If you think this could use functional testing, feel free to move it back. |
When an AMP response in paired mode has unsanitized validation errors, the behavior is to redirect to the non-AMP version. I realized that the response cache was not applying in this case when it could be. This PR explores what that can look like.