How can I test the CDN of Google's AMP Project?

落爺英雄遲暮 提交于 2019-11-30 05:34:43
Seth Yates

To use the AMP project CDN, you can access via a URL of the form:

https://cdn.ampproject.org/c/s/<origin-domain>/<path>

Note that the /s portion is optional and signals a secure origin, so if the origin isn't served over https, then you would use:

https://cdn.ampproject.org/c/<origin-domain>/<path>

So, if we take the following URL that has an AMP equivalent: http://www.theguardian.com/childrens-books-site/2016/jan/12/sugar-tax-andy-mulligan-liquidator, looking at the source, we see the following link:

<link rel="amphtml" href="https://amp.theguardian.com/childrens-books-site/2016/jan/12/sugar-tax-andy-mulligan-liquidator">

So, we can form a CDN URL for that AMP document as:

https://cdn.ampproject.org/c/s/amp.theguardian.com/childrens-books-site/2016/jan/12/sugar-tax-andy-mulligan-liquidator

Source: https://github.com/ampproject/amphtml/blob/master/src/service/cid-impl.js#L201

The CDN URL will change in 2017: https://developers.googleblog.com/2016/12/amp-cache-updates.html

Example from above:

https://amp-theguardian-com.cdn.ampproject.org/c/s/amp.theguardian.com/childrens-books-site/2016/jan/12/sugar-tax-andy-mulligan-liquidator

For a text example with http:

http://example.com/blog/index.html

Cache URL is:

https://example-com.cdn.ampproject.org/c/example.com/blog/index.html

With https:

https://example.com/blog/index.html

Cache URL is (notice the /s/):

https://example-com.cdn.ampproject.org/c/s/example.com/blog/index.html

For an image, replace the /c/ with /i/, for example,

http://example.com/blog/picture.jpeg

Cache URL is:

https://example-com.cdn.ampproject.org/i/s/example.com/blog/picture.jpeg

More details on cache URL name construction and name construction tools can be found here: https://developers.google.com/amp/cache/overview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!