Several days ago, I was asked to give a visual facelift to one of our sites Outdoor Is Life. The website contains thousands of upcoming hiking events in the country and already has an existing, fully functional AMP support.
Part of the update was to re-layout content elements, inject custom components, and add burger menu on AMP pages. The goal was to make all AMP pages to look as close as possible to our standard, non-AMP version.
Since our AMP contents are already being cached by Google, we can’t wait to let Google invalidate those outdated pages (which we really don’t know when to be honest). So we had to take action and force update those old AMP pages being cached by Google. And that’s where it gets a bit tricky, as we’re dealing with thousands of entries and we don’t want to do it one by one.
So I thought of sharing this guide so you too can save time in batch updating cached AMP pages.
Flush AMP Pages Cache In Bulk — Quickest Way to Invalidate Google AMP Cache
Time needed: 10 minutes
Here’s how to force update and purge cached AMP contents in bulk and instruct Google to serve our freshly revamped AMP pages
- Get the list of all blog or custom post URLs
Smart SEO CSV Import/Export’s export functionality could have easily done if for you but of course other export plugins will do as long as it can export full post URLs.
As soon as you have the list, put them in a events-post.txt file one URL per line - From that list, obtain its update-cache request URLs
Google AMP documentation indicates that you can flush any cached AMP contents by issuing update-cache request. Put simply, you’ll need to access a specially-formatted URL to invalidate an AMP content.
Suppose this is your standard post URL:
https://outdoorislife.com/event/taal-volcano/
Its AMP update-cache URL would be:
https://cdn.ampproject.org/c/s/outdoorislife.com/event/taal-volcano/amp/
Do the same for the rest of the URLs, so you events-post.xml will look something like this: - Send initial update-cache request to Google
Now that your list of URL is ready, time to ping Google. You could simply copy and paste them on your browser one by one, but it’s going to take you forever if you’re dealing with thousands of entries.
A more efficient way to invalidate AMP pages is to bulk access those URLs via CURL.
If you’re on Mac, just launch your Terminal and navigate to that folder where your events-post.txt file resides. Execute the following command:
xargs curl -sw “%{url_effective}\t %{http_code}\t %{redirect_url}\n” < events-post.txt
The above action could take several seconds depending on the total number of URLs to crawl. - Redo step 3 above
AMP content should now be refreshed from Google cache but since Google follows stale-while-revalidate method, the updated version will only be served to the next user (not you).
But here’s a neat trick: ping the same URLs again and you’re good to go.
You’re done.
Wrapping it up
If you’re a webmaster maintaining tens of customers’ websites, it’s not uncommon to push regular updates on those sites. Occasional content updates for instance ensures your readers get the most recent information from your site while a visual update ensures your users get the most delightful experience interacting your site.
When doing so, just make sure you purge your site’s cache and flush outdated AMP contents from Google’s server by following the guide above.
SEE ALSO: How To: Bulk Update Yoast SEO Meta Data or All-In-One SEO Pack Using CSV