AMP page experience beyond the cache

Core Web Vitals have given developers a standardized way to measure real-world user experience across loading speed, responsiveness and content stability. These metrics matter not just for user satisfaction but also because they will factor into Google Search's upcoming page experience ranking update. For sites built with AMP, the framework's static layout system helps prevent content shifts by design, but that alone doesn't guarantee strong Core Web Vitals scores.

Several performance-critical optimizations must happen server-side: image optimization, fast server-response times and effective font loading. AMP pages served from an AMP Cache in Google Search or Bing get these optimizations automatically, but direct visits to your origin — say, via a shared social link — don't get the same treatment. To deliver a consistent experience to all users, AMP pages need to be optimized before they leave your infrastructure.

Improve your page experience with AMP and Cloudflare Workers Unbound

AMP Optimizer on Cloudflare Workers

The AMP team previously released AMP Optimizer integrations for NodeJS and PHP. Both take an AMP HTML document as input and output an optimized version, but integrating them requires either building AMP optimization into your build system, running a node or PHP backend, or controlling your hosting environment. That's not always practical.

The new Cloudflare Worker integration removes those constraints. Instead of modifying your CMS or server, you deploy the optimizer as a Worker that sits in front of your origin and handles AMP optimization entirely at the edge. Instructions are available in the cloudflare-amp-optimizer repository.

How requests are handled

When a request for an HTML file arrives, the Worker first checks the global cache for an already-optimized version. If none exists, it fetches the file from your origin, detects whether it's an AMP document, and if so runs the optimizer before returning the response to the user. The generated version is only written to the cache after the response has been fully delivered to the client.

On subsequent requests from any Worker location worldwide, the optimized document is retrieved from the global KV cache, cached locally in that data center, and returned directly.

Preloading and responsive images

Because the AMP Optimizer parses the full HTML document, it can discover external resources and automatically add preload tags for fonts and hero images. For Cloudflare customers on Business or Enterprise plans, it can also generate image source sets that point to the Cloudflare Image Optimizer, giving the browser multiple image sizes to choose from based on viewport. This is particularly beneficial for mobile users who need far smaller images than desktop viewers with large displays.

CPU headroom with Workers Unbound

Most requests handled by the Worker complete quickly, but optimizing larger documents can exceed 50ms of CPU time. Cloudflare's Workers Unbound runtime raises the execution limit to 30 seconds, giving the AMP Optimizer enough headroom to process large files without users encountering errors. That makes Workers Unbound a natural fit for this workload.

Measuring the gains

Web performance can't be proven by a single synthetic test, and you should benchmark your own pages. That said, the AMP team has published an example WebPageTest comparison of an AMP page with and without the Worker-based optimizer in front of it, tested on a simulated Moto G4 over fast 3G. There's also an example benchmark script you can adapt for your own testing.

For AMP sites that need to score well on Core Web Vitals regardless of how users arrive, running AMP Optimizer at the edge via Cloudflare Workers is a low-friction path: no backend changes, no build-system modifications, and with Workers Unbound, enough execution time for even complex documents.