【问题标题】:How can I test the CDN of Google's AMP Project?如何测试 Google 的 AMP 项目的 CDN?
【发布时间】:2023-12-21 00:02:01
【问题描述】:

引自此处:https://www.ampproject.org/docs/get_started/about-amp.html

AMP 是一种为快速呈现的静态内容构建网页的方法。 AMP 在行动中由三个不同的部分组成:

  • AMP HTML
  • AMP JS
  • AMP CDN

AMP HTML 是一种 HTML,在可靠性方面存在一些限制,并且 一些扩展,用于构建基本 HTML 之外的丰富内容。放大器 JS 库确保 AMP HTML 页面的快速呈现。 AMP CDN (可选)提供 AMP HTML 页面。

引自此处:https://www.ampproject.org/how-it-works/

Google 正在提供一种服务,可以提供给定的 AMP HTML 文档 通过其 CDN 访问他们的 URL。

我在哪里可以找到这个 CDN 服务,以便我可以测试它?我google了很多,但我找不到任何信息。

【问题讨论】:

标签: google-cdn amp-html


【解决方案1】:

要使用 AMP 项目 CDN,您可以通过以下形式的 URL 访问:

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

请注意,/s 部分是可选的,表示安全来源,因此如果来源不是通过 https 提供的,那么您可以使用:

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

因此,如果我们采用以下具有 AMP 等效项的 URL:http://www.theguardian.com/childrens-books-site/2016/jan/12/sugar-tax-andy-mulligan-liquidator,查看源代码,我们会看到以下链接:

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

因此,我们可以为该 AMP 文档形成一个 CDN URL:

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

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

【讨论】:

  • 谢谢赛斯。那么有没有办法直接缓存监护人网站呢?我建立了这个小型 AMP 网站进行测试:jure.it 验证器不会返回任何错误,但 CDN 会:cdn.ampproject.org/c/s/jure.it 我错过了什么?谢谢
  • 看起来问题出在您页面上的这个标签上:&lt;a href="/whishlist/?1452809004""&gt;,特别是额外引号的问题。
  • 所以它也需要有效的 HTML,很高兴知道!如果我想直接缓存 jure.it,而不通过 ampproject.org,我必须做什么? (就像 cloudflare 一样)
  • 最初的问题是“我在哪里可以找到这个 CDN 服务,所以我测试一下?我搜索了很多,但我找不到任何信息。”我提供了一个答案。如果这回答了你的问题,请接受我的回答。至于其他的 CDN,我还不知道还有其他的,但是没有什么可以阻止您或其他人使用该项目建立自己的 CDN。
  • 你说得对,赛斯,我为那个问题开了一个new thread。谢谢。
【解决方案2】:

CDN URL 将在 2017 年发生变化: https://developers.googleblog.com/2016/12/amp-cache-updates.html

上面的例子:

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

【讨论】:

    【解决方案3】:

    对于带有 http 的文本示例:

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

    缓存网址是:

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

    使用 https:

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

    缓存 URL 是(注意 /s/):

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

    对于图像,将 /c/ 替换为 /i/,例如,

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

    缓存网址是:

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

    有关缓存 URL 名称构建和名称构建工具的更多详细信息可以在这里找到:https://developers.google.com/amp/cache/overview

    【讨论】:

      【解决方案4】:

      如果您访问 AMP 开发人员文档中的 Using the Google AMP Cache page,则会有一个文本框,您可以在其中输入您的原始 URL,它会显示相应的 AMP 缓存 URL。

      【讨论】: