How to manually update the AMP cache

Introduction

Pages that support AMP are cached by the provider on the Google side, and the cached pages are delivered from there, achieving high-speed web pages. So the question is how to update the cached page. This article describes how to manually update the AMP cache using a mechanism called update-cache. In WordPress etc., when you update the article, you need to update the cache of the AMP page as well.

procedure

  1. Create a private key and public key
  2. Place the public key on the application server
  3. Create a program that requests update-cache
  4. Run update-cache

Create private key and public key

Create a private key and public key locally.

$ openssl genrsa 2048 > private-key.pem
$ openssl rsa -in private-key.pem -pubout > apikey.pub

Place the public key on the application server

Place the public key on the server. Please place it in the following location.

/Document root/.well-known/amphtml/apikey.pub

You need to add "text / plain" to the content type in the web server configuration file. This is the setting method for Nginx.

/etc/nginx/mime.types


types {
     #Add to the end
     text/plain    pub;
}

nginx reboot

$ sudo systemctl restart nginx

Make sure that the public key "apikey.pub" is accessible and that the content type is "text / plain".

$curl -I https://example.com/.well-known/amphtml/apikey.pub

If the HTTP part and content-type part are displayed as shown below, you can set them without any problem.

HTTP/2 200
content-type: text/plain

Creating a program that requests update-cache

Originally, refer to Google's official document "Update AMP content" and update using a manually created key. -I make a cache request, but I'm grateful to use it because there is a predecessor who creates a series of flows with a shell script. https://github.com/sizaki30/google-amp-update-cache

After downloading the script, change the private key location.

# private_Change the key part.
private_key='/Specify the location of the private key with the full path/private-key.pem'

Upload the script anywhere on the server.

Run update-cache

Run the script, specifying the URL of the page for which you want to update the AMP cache. (It is recommended to quote the URL.) If "OK" is displayed, the update-cache request is successful.

$sudo sh google-amp-update-cache.sh 'https://example.com/test.html'
OK

Recommended Posts

How to manually update the AMP cache
How to update easy_install
How to update Spyder
How to use the generator
How to update Python Tkinter to 8.6
How to update with SQLAlchemy?
How to use the decorator
How to increase the axis
How to start the program
How to calculate the autocorrelation coefficient
How to use the zip function
How to use the optparse module
How to update Spyder in Anaconda
How to read the SNLI dataset
How to get the Python version
[Python] How to import the library
How to overwrite the output to the console
How to use the ConfigParser module
[Linux] How to disable the automatic update of the /etc/resolv.conf file (AmazonLinux2)
How to update the python version of Cloud Shell on GCP
How to display the progress bar (tqdm)
How to use the Spark ML pipeline
How to check the version of Django
How to solve the bin packing problem
How to set the server time to Japanese time
[Linux] How to use the echo command
How to use the Linux grep command
How to update php on Amazon linux 2
How to get colored output to the console
How to operate Linux from the console
How to update security on CentOS Linux 8
How to access the Datastore from the outside
How to use the IPython debugger (ipdb)
How to assign multiple values to the Matplotlib colorbar
How to calculate the volatility of a brand
How to use the C library in Python
How to specify the launch browser for JupyterLab 3.0.0
How to find the area of the Voronoi diagram
How to specify the NIC to scan with amazon-dash
[Python] How to change the date format (display format)
When you want to update the chrome driver.
How to try the friends-of-friends algorithm with pyfof
How to use the graph drawing library Bokeh
How to update security on Ubuntu 19.10 Eoan Ermine
How to print debug messages to the Django console
How to use the Google Cloud Translation API
How to operate Linux from the outside Procedure
How to use the NHK program guide API
[Algorithm x Python] How to use the list
How to erase the characters output by Python
How to measure line speed from the terminal
How to get the files in the [Python] folder
How to identify the system call number ausyscall
[TF] How to specify variables to update with Optimizer
How to Learn Kaldi with the JUST Corpus
How to find the correlation for categorical variables
Read the Python-Markdown source: How to create a parser
How to create an article from the command line
How to retrieve the nth largest value in Python
How to get the variable name itself in python
Think about how to program Python on the iPad