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

Change ?amp to ?amp=1 #1390

Closed
wants to merge 2 commits into from
Closed

Conversation

ricardobrg
Copy link
Contributor

@ricardobrg ricardobrg commented Sep 1, 2018

Usually the static cache configuration (nginx, static html files, proxy, etc) tells the server to bypass cache if the query string is not empty. Since 1.0 the amp URLs use ?amp and that prevents the server from caching it.

It's really easy to add a rule that tells the server to cache a page if a non-empty query arg is present but it's not easy to work with empty query args.

I've changed amp query var to amp=1 to make it possible to the server or cache and CDN services detect if amp query arg is present and deliver cached content.

Fixes #1383.

@@ -85,7 +85,7 @@ function amp_get_permalink( $post_id ) {
if ( current_theme_supports( 'amp' ) ) {
$permalink = get_permalink( $post_id );
if ( ! amp_is_canonical() ) {
$permalink = add_query_arg( 'amp', '', $permalink );
$permalink = add_query_arg( 'amp', '1', $permalink );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go ahead with this PR, then what we should do is take the opportunity to factor out the redundant formation of the AMP URLs with a new common function. There is presently amp_get_permalink() but that is specifically for getting URLs for posts. The amp_get_url() function would be used inside of amp_get_permalink().

There could be an amp_get_url() function that looks like this:

/**
 * Get the AMP version of a URL.
 *
 * This simply appends the required query parameter to the URL. It does not confirm
 * whether or not AMP is allowed on the given URL. If AMP is not supported, then a redirect
 * to the non-AMP version will ensue.
 *
 * @see amp_get_permalink()
 * @return string AMP URL.
 */
function amp_get_url( $url ) {
    return add_query_arg( amp_get_slug(), '1', $url );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter I'll work on it...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardobrg are you working on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @westonruter! Getting back to this now...

@westonruter westonruter changed the title fix #1383 change ?amp to ?amp=1 Change ?amp to ?amp=1 Sep 4, 2018
@westonruter westonruter added this to the v1.0 milestone Sep 4, 2018
@westonruter westonruter modified the milestones: v1.0, v1.1 Dec 4, 2018
@westonruter westonruter removed this from the v1.1 milestone Mar 6, 2019
@swissspidy
Copy link
Collaborator

@ricardobrg Would you still be interested in bringing this into the finish line? 🙂

@ricardobrg
Copy link
Contributor Author

@swissspidy yes! It is in my "todo list". I need to update the code and work in the feature. Give me one more week and I'll have another commit to this PR.

@westonruter
Copy link
Member

I think we'll need to step back and re-consider this at a higher level. There are some negative side effects to changing the AMP URLs. See #2204. I suggest we close this PR and take into account all the points in that issue in a new PR. It will require deeper changes than just changing the URLs.

@ricardobrg
Copy link
Contributor Author

Since this PR is almost 1 year old and lots of changes were made in the plugin, it will need a deeper work anyway. I will follow @westonruter suggestion and start working from #2204 considering the other related issues.

@ricardobrg ricardobrg closed this Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use query arg 'amp=1' instead of 'amp' for caching purposes
3 participants