Title: Optimize AMP
Last modified: November 30, 2021

---

# Optimize AMP

 *  Resolved [seo90](https://wordpress.org/support/users/seo90/)
 * (@seo90)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/optimize-amp/)
 * Hi, I’m using your plugin and a theme that I’m making following all the AMP.dev
   recommendations.
 * [https://amp.dev/documentation/guides-and-tutorials/optimize-and-measure/optimize_amp/](https://amp.dev/documentation/guides-and-tutorials/optimize-and-measure/optimize_amp/)
 * Here it indicates several things… One of them is the preloading of the AMP v0.
   js file.
 *     ```
       <!doctype html>
       <html ⚡ lang="en">
         <head>
           <meta charset="utf-8">
           <meta name="viewport" content="width=device-width">
           <meta name="description" content="This is the AMP Boilerplate.">
           <link rel="preload" as="script" href="https://cdn.ampproject.org/v0.js">
           <link rel="preload" as="script" href="https://cdn.ampproject.org/v0/amp-experiment-0.1.js">
           <link rel="preconnect dns-prefetch" href="https://fonts.gstatic.com/" crossorigin>
           <script async src="https://cdn.ampproject.org/v0.js"></script>
           <script async custom-element="amp-experiment" src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js"></script>
           <!-- Import other AMP Extensions here -->
           <style amp-custom>
             /* Add your styles here */
           </style>
           <link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet">
           <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible.selected}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible.selected}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible.selected}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible.selected}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible.selected}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
           <link rel="canonical" href=".">
           <title>My AMP Page</title>
         </head>
         <body>
           <h1>Hello World</h1>
         </body>
       </html>
       ```
   
 * The strange thing is that the English version of the documentation does not show
   such an example and does not talk about it. But in the German, French, Spanish
   versions… Yes, it does. So, should I preload the v0.js or not, and if the answer
   is yes. Should I preload v0.js or v0.mjs? because as I see in chrome what is 
   downloaded in the browser is the .mjs and not the .js?
 * Should I preload some of the other js that I use from AMP? like for example the
   cookie consent that is shown when you enter the website…?
 * Another question I have is regarding custom fonts.
 * `<link rel="preload" as="font" href="/bundles/app/fonts/helveticaneue-roman-webfont.
   woff2" >`
 * I want to preload it and put it as high as possible… After the first <meta> tags
   as indicated in the google documentation… But, if I put it in the header.php 
   as high as possible, the AMP plugin moves the code further down… I have also 
   tried adding a wp_head action with priority -9999 and it still puts it too low.
 * I am using AMP version on the whole website and not only for people coming from
   Google, so I would like to optimise it as much as possible.
 * Thank you.
    -  This topic was modified 4 years, 6 months ago by [seo90](https://wordpress.org/support/users/seo90/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [James Osborne](https://wordpress.org/support/users/jamesosborne/)
 * (@jamesosborne)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/optimize-amp/#post-15117168)
 * Hi there [@seo90](https://wordpress.org/support/users/seo90/),
 * The plugin will automatically request the AMP library scripts using recommended
   guidelines. While it doesn’t preload the v0.js/v0.mjs scripts you can visit [a previous support topic](https://wordpress.org/support/topic/preload-amp-runtime-2/#post-15116141)
   for an example code snippet which you can use if you wish. As tested previously
   this may slow down rendering. The full code snippet with slight modifications
   to that in the topic is below:
 *     ```
       /**
        * Preload AMP runtime scripts.
        */
       function amp_preload_amp_runtime() {
       	echo sprintf( '<link as="script" href="%s" rel="preload" crossorigin="anonymous">', esc_url( 'https://cdn.ampproject.org/v0.js' ) );
       	echo sprintf( '<link as="script" href="%s" rel="modulepreload" crossorigin="anonymous">', esc_url( 'https://cdn.ampproject.org/v0.mjs' ) );
       }
   
       add_action( 'wp_head', 'amp_preload_amp_runtime' );
       add_action( 'amp_post_template_head', 'amp_preload_amp_runtime' );
       ```
   
 * > The strange thing is that the English version of the documentation does not
   > show such an example and does not talk about it.
 * This is interesting, I’ll take this up with the team and see what they say. Many
   thanks for highlighting this.
 * > So, should I preload the v0.js or not, and if the answer is yes. Should I preload
   > v0.js or v0.mjs? because as I see in chrome what is downloaded in the browser
   > is the .mjs and not the .js?
 * The plugin also handles this. Depending on the browser in use the correct version
   will be requested.
 * > Another question I have is regarding custom fonts…
   >  I want to preload it and
   > put it as high as possible… After the first <meta> tags as indicated in the
   > google documentation
 * We had a previous support topic in relation to this. If you check the below there
   is also a link to a mini plugin that can help improve the performance of Google
   fonts:
    [https://wordpress.org/support/topic/best-practice-for-google-fonts-in-standard-mode/](https://wordpress.org/support/topic/best-practice-for-google-fonts-in-standard-mode/)
 * Hopefully the above is of use. Let me know if you have any further queries on
   this.
 *  Thread Starter [seo90](https://wordpress.org/support/users/seo90/)
 * (@seo90)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/optimize-amp/#post-15117467)
 * everything is ok. But, the font I use is hosted on my server. I just want to 
   be able to insert
 * <link rel=”preload” as=”font” href=”<?php echo esc_url( get_template_directory_uri().’/
   assets/fonts/mulish.woff2′ ); ?>” type=”font/woff2″ crossorigin=”anonymous”>
 * Further up in the head… In the AMP documentation it says to put it after meta
   charset and meta viewport. I can’t manage to put it there… I have edited the 
   header.php of my theme leaving it like this:
 *     ```
       <!doctype html>
       <html <?php language_attributes(); ?>>
       <head>
       <meta charset="<?php bloginfo( 'charset' ); ?>">
       <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
       <link rel="preload" as="font" href="<?php echo esc_url( get_template_directory_uri().'/assets/fonts/mulish.woff2' ); ?>" type="font/woff2" crossorigin="anonymous">
       <link rel="profile" href="https://gmpg.org/xfn/11">
       <meta name="amp-consent-blocking" content="amp-analytics,amp-ad" />
       <?php wp_head(); ?>
       </head>
       ```
   
 * And the AMP plugin moves the preload link of the source code. I also tried with
   add_action wp_head with priority of -9999, 1, etc… And it always inserts it too
   low. How can I put it at the top after the meta charset and meta viewport in 
   the html of the page?
    -  This reply was modified 4 years, 6 months ago by [seo90](https://wordpress.org/support/users/seo90/).
    -  This reply was modified 4 years, 6 months ago by [seo90](https://wordpress.org/support/users/seo90/).
 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/optimize-amp/#post-15118908)
 * > So, should I preload the v0.js or not, and if the answer is yes. Should I preload
   > v0.js or v0.mjs? because as I see in chrome what is downloaded in the browser
   > is the .mjs and not the .js?
 * Just to recap this: from our [testing](https://wordpress.org/support/topic/preload-amp-runtime-2/#post-15116141),
   you should not preload the v0 script. The AMP plugin will automatically preload
   it [if needed](https://github.com/ampproject/amp-toolbox-php/blob/f357c4fc7354e7307efd708a23ad465b1c07588f/src/Optimizer/Transformer/RewriteAmpUrls.php#L276-L292),
   and that’s if the AMP Optimizer can’t perform server-side rendering. This is 
   handled automatically.
 * > And the AMP plugin moves the preload link of the source code. I also tried 
   > with add_action wp_head with priority of -9999, 1, etc… And it always inserts
   > it too low. How can I put it at the top after the meta charset and meta viewport
   > in the html of the page?
 * The AMP plugin bundles the AMP Optimizer and it includes a `ReorderHead` transformer
   is responsible for ordering the elements in the head: [https://github.com/ampproject/amp-toolbox-php/blob/f357c4fc7354e7307efd708a23ad465b1c07588f/src/Optimizer/Transformer/ReorderHead.php#L16-L32](https://github.com/ampproject/amp-toolbox-php/blob/f357c4fc7354e7307efd708a23ad465b1c07588f/src/Optimizer/Transformer/ReorderHead.php#L16-L32)
 * So that’s why the order is not the same as how you output it. The ordering in
   the Optimizer is tuned to be optimal, so it may be a case where the AMP documentation
   is out of date. If you’re seeing a performance problem because of the ordering,
   we’ll want to address it in the AMP Optimizer. Otherwise, if it is performing
   well then no further action is required.
    -  This reply was modified 4 years, 6 months ago by [Weston Ruter](https://wordpress.org/support/users/westonruter/).
 *  Plugin Support [Milind More](https://wordpress.org/support/users/milindmore22/)
 * (@milindmore22)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/optimize-amp/#post-15146650)
 * [@seo90](https://wordpress.org/support/users/seo90/)
    As we didn’t receive a 
   response I’ll mark this as resolved. Feel free to open a [new support topic](https://wordpress.org/support/plugin/amp/#new-post)
   if you require any further assistance.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Optimize AMP’ is closed to new replies.

 * ![](https://ps.w.org/amp/assets/icon.svg?rev=2527602)
 * [AMP](https://wordpress.org/plugins/amp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amp/)
 * [Active Topics](https://wordpress.org/support/plugin/amp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amp/reviews/)

 * 4 replies
 * 4 participants
 * Last reply from: [Milind More](https://wordpress.org/support/users/milindmore22/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/optimize-amp/#post-15146650)
 * Status: resolved