Google announced in November 2020 that page experience signals would be included in Google Search ranking. This means it is now more important than ever to ensure your website is optimised for speed. While this update is targeted at mobile, you may find your website is indexed mobile-first, which means the mobile version of your website is the first thing Google looks at when indexing your site.

One way to optimise your website for speed is to use Accelerated Mobile Pages (AMP). You can use AMP to serve a website completely, both desktop and mobile, just like the website you are on now. Otherwise, you can use AMP to serve a separate version of your pages, which is more common but a bit more cumbersome to manage as it means having to maintain different versions of your website.

Once you have your AMP pages ready, you can further optimise than by using an AMP Optimizer:

format_quote AMP Optimizers are tools that bring AMP Cache optimizations to your own site. Using an AMP Optimizer is key to creating a great page experience and achieving Core Web Vitals compliance. If you want to learn more about how an AMP Optimizer works, checkout our detailed AMP Optimizations Guide.format_quote

I chose to use AMP Toolbox for PHP as it allows me to take the AMP HTML from my PHP output and literally just convert it into the optimised AMP code - very simple!

Here are the steps I followed to set this up and use it for the very website you are on now!

Instructions: How to set up AMP Optimizer for PHP to get your AMP pages ready for Google's May 2021 update

1. Install Composer

To get all the relevant files for AMP Toolbox for PHP you can use Composer to download these.

Here are the installation instructions:

https://getcomposer.org/doc/00-intro.md

I am using a PC, so I followed the PC instructions:

format_quote Download and run Composer-Setup.exe. It will install the latest Composer version and set up your PATH so that you can call composer from any directory in your command line. format_quote

2. Use Composer to download the AMP Toolbox for PHP files

You can now use Composer to download the relevant files. Simply open up the command prompt on your computer e.g. on PC: Start > Run> cmd. Then navigate to your website folder and use the following command:

composer require ampproject/amp-toolbox 

3. Add the Optimizer PHP code to your PHP files

Once the files have been downloaded you can now use them in your PHP scripts as follows:

require 'includes/php/vendor/autoload.php';

use AmpProject\Optimizer\ErrorCollection;
use AmpProject\Optimizer\TransformationEngine;

$transformationEngine = new TransformationEngine();

$errorCollection = new ErrorCollection;

$optimizedHtml = @$transformationEngine->optimizeHtml(
   $unoptimizedhtml,
   $errorCollection
);

The $unoptimizedhtml variable above is your entire AMP page HTML. This may be a little bit tricky to sort out as often you may simply be outputting your HTML without putting it into one variable, but I do recommend you take some time to convert it to this way of doing things so that you can take advantage of the AMP optimizer.

4. Output the optimised AMP HTML to your page

You can now output the optimised AMP HTML to your page

echo $optimizedHtml;

5. Finally, analyze your AMP page

You can then use the AMP Page Experience Guide to measure your success:

https://amp.dev/page-experience/


You should now have fully optimised AMP HTML!