AMP & Furious

A presentation at Turin Web Performance Meetup in April 2018 in Turin, Metropolitan City of Turin, Italy by Matteo Fogli

Slide 1

Slide 1

AMP & Furious

Slide 2

Slide 2

Web Performance Turin Meetup

Slide 3

Slide 3

Matteo Fogli Web Performance Lead @Modo.md twitter: @pecus

Slide 4

Slide 4

(video, Ken Block starting a massively fast tuned car)

Slide 5

Slide 5

What is AMP?

Slide 6

Slide 6

AMP is like a fast car

Slide 7

Slide 7

AMP is HTML ⚡

Slide 8

Slide 8

AMP is a Web Component Format + JavaScript Library

Slide 9

Slide 9

AMP is strictly validated

Slide 10

Slide 10

What is AMP Recap

Accelerated Mobile Pages are HTML pages designed to be rendered fast AMP is a web component format + JS library, strictly validated AMP does not require any server side technology* and works in any browser

  • except for Caches

Slide 11

Slide 11

DRIVER ED

Slide 12

Slide 12

AMP 101

Anatomy of an AMP document

Slide 13

Slide 13

AMP 101

Slide 14

Slide 14

AMP 101

Slide 15

Slide 15

AMP 101

Slide 16

Slide 16

AMP 101

Slide 17

Slide 17

AMP 101

Slide 18

Slide 18

https://www.ampproject.org/

Slide 19

Slide 19

AMP Do’s and Don’ts

Slide 20

Slide 20

Simplified HTML

AMP has a Simplified HTML

Slide 21

Slide 21

Simplified HTML

No external resources 
 img becomes <amp-img>

video becomes <amp-video>

audio becomes <amp-audio>

iframe becomes <amp-iframe>

Slide 22

Slide 22

No JavaScript

Slide 23

Slide 23

CSS

Slide 24

Slide 24

CSS

50Kb single file CSS no inline styles no !important no filter: only GPU–accelerated CSS animations

Slide 25

Slide 25

SEO

Slide 26

Slide 26

SEO

SEO Self Canonicalize or use an alternate page Use <link rel="amphtml"> in alternate page
Ensure Content Parity Validate iteratively + fix errors

Slide 27

Slide 27

Validation

Slide 28

Slide 28

How to validate AMP

With your browser (append development=1 to URL) Web Interface: https://validator.ampproject.org/ Browser Extension NPM Packages for CI Command Line Tool

Slide 29

Slide 29

Development lifecycle issues

Validator via node Complex test environments vs. validation / iteration A/B testing Enforce user input / UGC

Slide 30

Slide 30

AMP 101 Recap

Subset of HTML + boilerplate No JS (iFrames / AMP Components) Light CSS (50Kb + fonts) Must validate (with browser, toolchain or process)

Slide 31

Slide 31

Ready to race?

Photo by Goh Rhy Yan on Unsplash

Slide 32

Slide 32

AMP Pros

Fast / Lightweight (mostly) Progressively Enhanced Open Source / somewhat standardised Publisher advantage (reach, higher CT rates, lower bounces)

Slide 33

Slide 33

Common misconceptions

Does AMP replaces websites? Are we back to the m-site nightmare of pre-responsive web? Will AMP sites look all the same? 50Kb of CSS is tiny! Is AMP a static site? no fancy JS stuff (no JS!)?

Slide 34

Slide 34

Great, right?

Slide 35

Slide 35

Enter Google News Carousel

Slide 36

Slide 36

Video by Ethan Marcotte

Slide 37

Slide 37

Great, right?

Slide 38

Slide 38

So, then, AMP…

Slide 39

Slide 39

AMP Cons

Proprietary (despite OSS) “Breaks” the web breaks URLs, scrolling issues, introduces 3rd party hosting Competitive advantage in News Carousel Associated cost (development, testing, maintenance)

Slide 40

Slide 40

How Can AMP Be So Fast?

Slide 41

Slide 41

How Can AMP Be So Fast?

Critical path is clear of blocking obstacles CSS (inline) JS (AMPified + async) Static layouting (elements have known sizes)

1 SINGLE HTTP REQUEST TO DISPLAY CONTENT

Slide 42

Slide 42

How Can AMP Be So Fast?

Critical path is clear of blocking obstacles CSS (inline) JS (AMPified + async) Static layouting (elements have known sizes)

1 SINGLE HTTP REQUEST TO DISPLAY CONTENT

Early font loading Prioritised resource loading (ATF)

Slide 43

Slide 43

Then add NOS…

Slide 44

Slide 44

NOS: AMP Caches

Caches play a fundamental role in AMP:

  • Ensure the document is valid (thus, fast)
  • Allow embedding
  • Allow image optimisation, source reordering, AMP post–processing
  • Allow pre–rendering (partial, prioritised)

Slide 45

Slide 45

NOS: AMP Caches

  • Ensure no Cross Scripting Issues when preloading
  • Modify JS URLs for better caching
  • Provide a privacy shield when content is pre-rendered

Slide 46

Slide 46

NOS: Preloading

https://medium.com/@pbakaus/why-amp-caches-exist-cd7938da2456

Slide 47

Slide 47

NOS: Preloading

  • Prerenders only ATF
  • No downloads of BTF elements
  • Does not execute 3rd party JavaScript
  • On average 75% of page is not pre-rendered

https://www.youtube.com/watch?v=hVRkG1CQScA

Slide 48

Slide 48

Recap

AMP Pros

  • Fast / Lightweight
  • Progressively Enhanced
  • Open Source / somewhat standardised
  • Preloading (News Carousel)

AMP Cons

  • Privately led OSS
  • Not a W3C standard
  • Less control over content
  • Improper advantage on SERP

Slide 49

Slide 49

Comparison

https://timkadlec.com/remembers/2018-03-19-how-fast-is-amp-really/

Slide 50

Slide 50

Comparison

  • AMP vs. separate canonical page
  • AMP pages are significantly lighter (905 KB vs. 2,762 KB) and load significantly fewer assets (61 vs. 318 requests)
  • There are significant extremes across the spectrum (heavily bloated pages, slow pages)

Slide 51

Slide 51

AMP page speeds

https://timkadlec.com/remembers/2018-03-19-how-fast-is-amp-really/

Slide 52

Slide 52

Enter the Cache

Google AMP Cache

  • CDN
  • caches AMP documents
  • applies a series of optimizations
  • provides a validation system

Slide 53

Slide 53

AMP page speeds

Slide 54

Slide 54

Google AMP Cache Delta

Slide 55

Slide 55

Canonical page speeds

Slide 56

Slide 56

Video Comparison

Canonical:

  • SpeedIndex: 5337
  • Start Render: 3600ms

AMP:

  • SpeedIndex: 4506
  • Start Render: 4033ms

AMP Cache:

  • SpeedIndex: 3546
  • Start Render: 2850ms

Slide 57

Slide 57

Advanced AMP

Slide 58

Slide 58

PWA + AMP

2 (and 1/2) Strategies

  1. AMP Up: use AMP as landing, then install SW and handoff to PWA
  2. AMP Down: use AMP as a SSoT for content (vs. Json) 2 1/2. Use a SW with AMP

Slide 59

Slide 59

PWA + AMP

Slide 60

Slide 60

PWA + AMP

Slide 61

Slide 61

AMP future

Standardization: Feature Policy, Web Packaging, iframe promotion, Performance Timeline, and Paint Timing.

Web Packaging format for providing privacy preserving pre-loading, no 3rd party caches

Custom JavaScript (Web Workers + Virtual DOM)

Origin URLs

See: https://github.com/ampproject/amphtml/blob/master/contributing/web-standards-related-to-amp.md

Slide 62

Slide 62

AMP Resources

https://ampbyexample.com https://ampproject.org The AMP Channel (YouTube) Malte Ubl @cramforce Paul Baukaus @pbakaus https://amphtml.wordpress.com

Slide 63

Slide 63

Amp & Furious

Driver: Matteo Fogli @pecus Production: TorinoWebPerf P.R. Agency: #webperformanceitalia Twitvertising: @trnwebperf Camera: Oleg Belousov