Cloudflare AMP Cache

Overview

Cloudflare's AMP Cache serves cached copies of valid AMP content published to the web. Serve content directly from Cloudflare's AMP Cache to provide a fast user experience. Cloudflare's AMP Cache network is distributed worldwide in 102 locations in 50 different countries.

To take advantage of Cloudflare's AMP Cache, an AMP URL must be accessed directly from the cache using the AMP Cache URL format. Each time a user accesses AMP content from the cache, the content is automatically updated, and the updated version is served to the next user once the content has been cached. Publishers can also serve their content from branded AMP Caches using Cloudflare's infrastructure.

To learn more about AMP visit ampproject.org.

AMP Cache URL Format

The URL consists of the following components:

Component Description
Content type The content type is one of the following: 'c' for an AMP HTML document, 'i' for an image, or 'r' for a resource such as a font. Cloudflare's AMP Cache returns a 404 error for resources that do not match these content types.
Optional 's' If present, requires that Cloudflare fetch the content from the origin using TLS (secure HTTPS). If the 's' is not present, then content gets fetched from the origin using plain HTTP.
URI URI of the content to be fetched. The URI cannot contain a scheme; that is, no http:// or https://.

Example requesting document using TLS

Request for an AMP page from

https://foo.com/amp_document.html

looks like:

https://amp.cloudflare.com/c/foo.com/amp_document.html

The 'c' here tells us that the content type is 'AMP HTML document'. If the url looks like:

https://amp.cloudflare.com/c/s/foo.com/amp_document.html

The extra 's' here will fetch the content from the origin using TLS over plain HTTP.

Example requesting image using plain HTTP

Request for an image fetched from http://foo.com/logo.png:

https://amp.cloudflare.com/i/example.com/logo.png

The 'i' prefix tells us that the content is an image.

Performance

Security

Reliability

Validation

In making the above transformations, Cloudflare's AMP Cache disregards the Cache-Control: no-transform header. We also provide a validation API for publishers to see if you AMP content is valid:

Validation API

curl -X POST --data-binary @invalid_amp.html -H 'Content-Type: text/html; charset=UTF-8' https://amp.cloudflare.com/q/
{"version":"1485227592804","source":"POST","valid":false,"errors":[{"line":13,"col":7,"code":"MANDATORY_TAG_MISSING","error":"The mandatory tag 'link rel=canonical' is missing or incorrect.","help":"https://www.ampproject.org/docs/reference/spec.html#required-markup"}]}
curl https://amp.cloudflare.com/q/amp.usatoday.com/story/82055560/
{"version":"1488238516283","source":"http://amp.usatoday.com/story/82055560/","valid":true}

AMP Cache Updates

When a user requests an AMP document from the Cloudflare's AMP Cache, the cache automatically requests updates in order to be able to serve fresh content for the next user once the content has been cached. With this model, updates to AMP documents propagate automatically and quickly; few users will see the non-updated version after your update.

The cache follows a "stale-while-revalidate" model. It uses the origin's caching headers, such as Max-Age, as hints in deciding whether a particular document or resource is stale. When a user makes a request for something that is stale, that request causes a new copy to be fetched, so that the next user gets fresh content.

To limit the amount of load it generates for publisher sites, Cloudflare's AMP Cache considers any document fresh for at least 15 seconds, and any resource fresh for at least 1 minute. Note that those numbers may change in the future, as we tune the cache for optimum balance between freshness and load on publisher sites