Today, after setting up the Cloudflare plugin for cache invalidation, we enabled APO again on our production sites. It had been on a while ago (not sure how long but not longer than 3 months ago) for long periods without any page experiencing issues.
However after turning it on all pages contained a 400 error message from Google at the start of the body, and an additional style tag in the head containing styles of that error page. The styles set a max width on the body, so it really messed up the layout too:
We quickly disabled APO and did a full CF purge, which resolved the issue.
The site is https://www.greenpeace.org/international/, but you currently can’t see the issue there. I’ll post a link here once we have reproduced it on another environment.
Now we wanted to set up APO for our test subdomain www-dev. We didn’t do this before enabling on production, because neither the plugin nor the Cloudflare dashboards allows administering the APO subdomains without enabling the setting first. Since APO had worked for us in the past we weren’t expecting any issues, or at least not issue that would break our site in this way.
We checked the documentation we could find about subdomains, which mentions
When activating APO on a subdomain as a part of the migration, APO will be disabled on a root domain automatically. If you are still interested in running APO against the root, please upgrade WordPress plugin version 3.8.6 or later on the root domain and re-enable APO.
That led us to assume that running the plugin from our www-dev subdomain site would allow us to turn on APO for that subdomain only. That turned out to not be the case, turning it on from there enabled APO for the root domain and www subdomain, again breaking our site and requiring a full purge to resolve.
Why doesn’t either the plugin or the Cloudflare dashboard simply allow administering the list of subdomains, including treating www no different than other subdomains? In the plugin code you can see that it sends a patch request to the zone settings (https://api.cloudflare.com/client/v4/zones/{{zoneId}}/settings/automatic_platform_optimization), which includes the hostnames.
Using the same API I was able to change these so they only have our develop and staging domains.
We haven’t tried turning APO on for that develop domain, we’ll wait for a lower traffic moment as we’re not entirely sure that turning on the option wouldn’t somehow add the root domain and www to the hostnames again.