amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Allow referencing AMP pages using Link response header

Open niutech opened this issue 9 years ago • 9 comments

This was previously published as a comment in issue #498 and in the AMP HTML discussion forum:

Please allow users to reference AMP pages not only using <link href="..." rel="amphtml"> HTML tags, but also using the Link: <....>; rel="amphtml" response header (as in RFC 5988), and please add this to the AMP spec.

The rationale is that by using the Link response header, a user agent does not have to download the response body in order to automatically redirect user to the AMP version of a web page (thus saving bandwidth and time). This could be achieved as a Chrome extension, which binds to webRequest.onHeadersReceived and redirects the request to the AMP page, without loading the canonical page first.

In my opinion, the Link response header should take precedence over the <link> HTML tag.

niutech avatar May 04 '17 11:05 niutech

/to @Gregable, @dvoytenko

jridgewell avatar May 04 '17 19:05 jridgewell

Overall, Link header is a standard thing. I believe some of AMP crawlers out have to use it already, since they often restitch such headers back into crawled html for passing it around. While it's a nice optimization, I'm not sure we can require Link header in all cases since it'd be a somewhat higher barrier comparing to the <link> in HTML.

/cc @alf7

dvoytenko avatar May 05 '17 16:05 dvoytenko

We definitely couldn't require a link header, because it wouldn't be backward compatible and would be difficult to implement for many sites.

It could be optional and take precedence, but then useragents would thus still need to download the document body, or make two requests (first a HEAD request, followed by a GET request if a link header is missing). I doubt that this pattern would offer a savings in practice to any useragents and thus would unlikely be implemented.

Gregable avatar May 08 '17 20:05 Gregable

This could be implemented by a Chrome extension intercepting the GET response in chrome.webRequest.onHeadersReceived when there is a Link header, so there will be savings at least in lack of parsing and rendering the HTML response, compared with searching the DOM for the tag.

niutech avatar May 09 '17 00:05 niutech

I think we can definitely go as far as recommending sending Link header for amphtml for canonicals.

dvoytenko avatar May 09 '17 19:05 dvoytenko

That would be great. Thank you.

niutech avatar May 10 '17 16:05 niutech

Yeah, this seems like a very reasonable thing to support, but as Greg and Dima pointed out, it's just an optimization.

alf7 avatar May 15 '17 15:05 alf7

There is nothing to actually do here, is there? Publishers can optionally add this header if they want, and useragents can optionally consume it if they want.

Gregable avatar Nov 09 '17 01:11 Gregable

@Gregable I think your closing this issue is premature, as there is one thing to do, which is adding to the AMP spec that user agents should support referencing AMP HTML using the Link: <....>; rel="amphtml" response header too, not only using the <link rel="amphtml" href="..."> tag.

niutech avatar Nov 09 '17 15:11 niutech