AMP pages version is never cached by Automatic Platform Optimization for Wordpress

Hello,

I am not able to make Automatic Platform Optimization for Wordpress to cache HTML pages in AMP version.
No page rules active.

Here you can find an example (multiple tests performed with Webpagetest.org):

Standard version

Response headers

cf-cache-status: HIT
x-via: speedwp/cache
cf-edge-cache: cache,platform=wordpress

AMP version

Response headers

cf-cache-status: DYNAMIC
x-via: speedwp/origin,qs
cf-edge-cache: cache,platform=wordpress

What should I do to make HTML edge caching to work also for AMP pages?

Thanks,
Emiliano.

To figure out the issue, you need to look at the parameters of the x-via header for the AMP pages. In your case, this is what you are getting: x-via: speedwp/origin,qs

Essentially, the x-via header tells you that you are using APO (speedwp), but that the content was NOT cached and returned from your web server (origin) because it has a query string (qs). In your case, the query string is ?amp= at the end of the URL. Right now, I believe APO is NOT caching pages with an ?amp query string. It will only cache AMP pages if they use the /amp/ slug.

I know @yevgen and his team have recently added some query strings to be safely ignored and cached by APO, and I think adding query strings for AMP pages would also make sense since not everyone uses the /amp/ slug. I know the developers of the Official AMP Plugin for WordPress are leaning towards an ?amp query string rather than the /amp/ slug, but discussion is still ongoing (https://github.com/ampproject/amp-wp/issues/2204).

So for the time being, if you want to be able to cache AMP pages with an ?amp= query string, you could always setup a Page Rule with a Cache Level of Cache Everything and the following URL match: https://lamiacasaelettrica.com/*?amp=

Hope this helps.

2 Likes

Thanks @janvitos

I’ll try your suggestion.

I think this is currently a huge limitation of Automatic Platform Optimization for Wordpress considering that I am using official AMP Plugin for WordPress that creates AMP pages exactly in the format of my example !

Now I applied a dedicated page rule, but I think the beahaviour is not exactly what is expected.

AMP Page (in the example before final = was wrong)

Response header

cf-cache-status: HIT
x-via: speedwp/origin,qs
cf-edge-cache: cache,platform=wordpress

As you can see I have still x-via: speedwp/origin,qs and not x-via: speedwp/cache.

That’s normal since the AMP pages are NOT being cached by APO, but by your Page Rule.

And you know your AMP pages are being cached property since you are getting the cf-cache-status: HIT header.

Thanks @janvitos for the research, we will add amp to the list of query strings we allow to return from Cache.

2 Likes

I would like to make it clear the result of this change. AMP plugins for WordPress make html pages AMP compliant. It means possibly serving amp pages for desktop and mobile clients. At the moment we serve all content from the single cache regardless of the form factor: desktop, mobile, tablet. We are considering separate cache for mobile clients.

Back to the change that will allow to serve “example.com/?amp=” from Cloudflare cache. It means depending on the AMP configuration on your site we may serve AMP pages where it wasn’t requested and non AMP pages where “?amp=” was present.

2 Likes

The change is live.

1 Like