0

Matt Mower posted a gist explaining how to self-host AMP framework.

One of the benefits he counts is:

serve AMP pages and the framework from the same host, potentially improving content delivery times.

Before reading this, i thought there isn't a difference in performance, because HTML is served once from my server, then async calls transfer the AMP framework files from official CDN. If self-hosted, AMP framework files will still be served almost the same way, but from my server. So how is self-host AMP framework perform better?

Dorad
  • 3,413
  • 2
  • 44
  • 71
  • the topic is 'host of libraries', not 'host of content'. your 'hosted' site would point to hosted javascript rather than amp-javascript. you need to check whether your content, with hosted libs, is in the amp-cache (i can't remember without checking) – Jay Gray Apr 14 '20 at 14:54

1 Answers1

1

Keep in mind that, while the AMP libraries are loaded asynchronously, the AMP runtime (v0.js) is still render-blocking for your pages (this is done on purpose using the AMP CSS boilerplate which hides the page content until the runtime loads).

Assuming your server supports HTTP/2, hosting the runtime alongside your website allows you take advantage of request multiplexing and avoids connecting to a different server (the AMP CDN) which normally adds DNS lookup and connection overhead.

However, there are disadvantages to self-hosting the framework:

  • Your pages become invalid AMP (this will change in the future).

  • AMP's CDN is globally distributed and very performant - if you don't use a similar quality CDN yourself, CDN performance may outweigh the advantages introduced from hosting the runtime on the same server as your website.

  • Browsers may have cached the AMP runtime served from the AMP CDN if you previously visited another AMP website (this doesn't apply to browsers with a double-keyed cache like Chrome).


Bottom line is, if you're aiming for higher performance on AMP pages, it's best to start with the tips outlined in How to make AMP even faster and implement server-side rendering. Self-hosting the framework may yield additional performance benefits, but for most websites this is likely negligible.

fstanis
  • 5,234
  • 1
  • 23
  • 42
  • Two additions: 1. self-hosting the AMP runtime will be supported by the AMP validator in the future. 2. browsers nowadays cache scripts only per origin so cross origin caching is no longer a benefit of loading the AMP runtime from cdn.ampproject.org. – Sebastian Benz Apr 20 '20 at 07:39