AMP
  • websites

Using the Google AMP Cache

Introduction

The Google AMP Cache stores valid AMPs and provides a consistently fast access to AMPs. It is available for anyone to use.

AMP Cache URL Format

When possible, the Google AMP Cache will create a subdomain for each AMP document's domain by first converting it from IDN (punycode) to UTF-8. The caches replaces every - (dash) with -- (2 dashes) and replace every . (dot) with - (dash). For example, pub.com will map to pub-com.cdn.ampproject.org.

Here is AMP Cache URL for https://amp.dev/about/websites/:

The converted AMP Cache URL consists of the following parts:

  • amp-dev: the publisher domain converted into a subdomain using the algorithm described above.
  • cdn.ampproject.org: the AMP Cache domain.
  • c: to indicate that it's an AMP document (there is also i for image and r for resources such as fonts).
  • s: indicating that the AMP Cache fetches the content from the origin using TLS (secure HTTPS).
  • amp.dev/examples/components/amp-img: the original URL excluding the scheme.

It is OK for URLs to include parameters in the query string, simply include these in the AMP Cache URL as well.

Example: https://amp-dev.cdn.ampproject.org/c/s/amp.dev/documentation/examples/api/query?value=Hello%20World.

Cache updates

The AMP Cache uses a one-behind caching model which can be controlled by the max-age cache directive. You can test the behavior with this sample page, which will prints the current date at serving time:

Max-age 15s: https://amp-dev.cdn.ampproject.org/c/s/amp.dev/documentation/examples/api/query?maxage=15.

Redirect & Error Handling

Here are some examples for how the AMP Cache handles redirects and errors:

Redirects

The AMP Cache follows redirects when resolving AMP URLs. For example, if an URL redirects to another AMP URL:

$ curl -I https://ampbyexample.com/components/amp-img/

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: https://amp.dev/documentation/examples/components/amp-img/
...

Then the AMP Cache will return the content of the resolved redirect for the original URL.

Example: https://amp-dev.cdn.ampproject.org/c/s/ampbyexample.com/components/amp-img/.

If you move the location of the AMP Files on your server, make sure to set up a redirect from the old location to the new one.

Not Found

When a page is not found in the AMP Cache, it will show an error page and return a 404 status.

Example: https://amp-dev.cdn.ampproject.org/amp.dev/not-found

Invalid AMP

When a page is invalid AMP, the AMP Cache will return a 404 status.

Example: https://amp-dev.cdn.ampproject.org/amp.dev/static/samples/files/invalid_amp.html

Server Errors

If an URL returns a 5XX server errors, the AMP Cache will return a 404 status.

Example: https://amp-dev.cdn.ampproject.org/amp.dev/documentation/examples/api/error

자세한 설명이 필요하신가요?

이 페이지의 설명만으로 궁금한 점이 모두 해결되지 않는다면 다른 AMP 사용자에게 문의하여 구체적인 활용 사례를 논의해 보세요.

Stack Overflow로 이동
설명이 부족한 기능을 발견하셨나요?

AMP 프로젝트는 여러분의 참여와 기여를 적극 환영합니다! 오픈 소스 커뮤니티를 통해 지속적으로 활동해 주셔도 좋지만 관심 있는 주제에 한 번만 기여하셔도 큰 도움이 됩니다.

GitHub에서 샘플 수정하기