Amp-wp: Use query arg 'amp=1' instead of 'amp' for caching purposes

Created on 30 Aug 2018  路  10Comments  路  Source: ampproject/amp-wp

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.

If we change ?amp to ?amp=1 it will have the same effect in rewrite rules and will make it possible to the server detect if amp query arg is present and deliver cached content.

All 10 comments

That's good to know. The main reason for the plugin creating amphtml links with ?amp instead of ?amp=1 is that it looks prettier, which is not really a great reason.

Here is where that link is generated:

https://github.com/Automattic/amp-wp/blob/c539a18196dec51d6b8d443ee14736f9ebffa3c7/includes/amp-helper-functions.php#L196

What is the rule you're using in your server to successfully cache for ?amp=1?

@westonruter I already have a working code but I'm still working on the tests. It works as expected but the tests still wait for ?amp instead of ?amp=1. I will make a PR so we can discuss it further.

I use nginx fastcgi cache and it detects if a query param is present with $arg_{param_name}. So it's easy to check if it is present and set cache_bypass to false like this:

if ($arg_amp) {
    set $skip_cache 0;
}   

But if the param is empty (or 0) it doesn't detect...

Could you not do:

if ($arg_amp != false) {

The problem is that if amp param has no value in the URL, $arg_amp never gets defined. It's the same thing to have ?amp or nothing. The only way to do it with ?amp with no value, would be use regex in query string. It can be done, but it would decrease the compatibility with cache and CDN services that use $amp_{param_name} to check if the param is in the URL and get its value.

Something that came up was whether ?amp=1 would imply that you could do ?amp=0 to disable AMP. Since 1 doesn't really mean anything otherwise, what if we did ?amp=on similar to the default value for submitting a checkbox, or instead what if we did ?amp=鈿★笍, which would be cool. Only concern I have about that is whether the emoji would cause any problems with URL. But that concern may not be valid.

_But_ since #1455 it is now possible to customize the query var from amp to lite for example. It wouldn't make sense to see ?lite=鈿★笍. So maybe we should just go with 1. /cc @kienstra

Moving To v1.1 Board

If it's alright, I'm moving this to the v1.1 board, as it looks like this won't be part of v1.0-RC1.

@westonruter what is the status of this issue? Is there yet any work to be done in it?

@ricardobrg It hasn't been touched since you wrote this: https://github.com/ampproject/amp-wp/pull/1390#discussion_r227732597

Closing in favor of #2204.

Was this page helpful?
0 / 5 - 0 ratings