Derek
Derek

Reputation: 11915

How to force page into amp cache?

I have posted an example AMP page onto a heroku project;

http://boiling-garden-78683.herokuapp.com

I have then tried to use the following curl command to get the AMP cache URL:

curl -i -s -k -X POST -H "Content-Type: application/json" -H "X-Goog-Api-Key:<MYKEY>" -d "{urls: ['http://boiling-garden-78683.herokuapp.com/']}" "https://acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet"

This curl command is returning:

{
  "urlErrors": [
    {
      "errorCode": "NO_AMP_URL",
      "errorMessage": "No AMP URL for the request URL.",
      "originalUrl": "http://boiling-garden-78683.herokuapp.com/"
    }
  ]
}

What am I not understanding about AMP? Isn't the whole purpose of making an AMP page so that I can get an AMP URL to give to users instead of them having to go to my site directly?

Upvotes: 1

Views: 1446

Answers (2)

Gregable
Gregable

Reputation: 498

You can also directly construct the AMP Cache URL. The logic is pretty simple: remove the protocol (http:// in this case), and prefix https://cdn.ampproject.org/c/. If your page is served from https, you would use https://cdn.ampproject.org/c/s/.

But yes, the API you are using only returns results that have already been cached. You can prime the cache with the update-ping URL that Nick provided and then it should work.

Upvotes: 0

Nick
Nick

Reputation: 225

You have two options:

  1. Wait when will google crawler find your pages changes

  2. Just do this call by "curl" or just go the link using browser:

    curl https://cdn.ampproject.org/update-ping/c/s/boiling-garden-78683.herokuapp.com

Then the API call you provided will return what you want ;) Mechanism of updating AMP cache (or if not in cache it will add if your AMP is valid) is described on this Update AMP Content page.

Upvotes: 3

Related Questions