Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AMP is a Thing for Programmers

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

AMP is a Thing for Programmers

AMP was created to make simple websites faster. It's grown into a full-featured web components library that aims to make the web easier for users and developers alike! It restricts the use of JavaScript - so how might it be good for programmers?

Raghu and I discuss how AMP aims to bring the best of the web to everyone even before they write a line of JavaScript. But also:

• You can create user interactions using binding, JS state objects, and JS expressions
• AMP works well with PWA
• The just-released WorkerDOM library is part of an effort to allow multithreaded JS in AMP, using Workers
• Everyone is encouraged to contribute to the AMP open-source project.

Avatar for Ben Morss

Ben Morss

August 25, 2018

Other Decks in Programming

Transcript

  1. 2 Ben Morss - Ben Morss é um Developer Advocate

    no Google, onde trabalha focado em aprimorar a Web a ser mais rápida e mais bonita. Antes do Google, ele era um músico em tempo integral. - @benmorss
  2. Raghu Simha Technical Lead (Infrastructure), AMP - Raghu simha é

    engenheiro de software baseado em NYC na equipe de amp do Google, que desenvolve as ferramentas e a infraestrutura usadas pelos engenheiros da AMP e pelos colaboradores externos. @rsimha on GitHub 3
  3. 7 of consumers will abandon a site if it takes

    longer than 3 seconds to load. 53% (data from Google Analytics)
  4. 11 An open source initiative to enable a better web,

    with sites that are fast, easy to create, and mobile-friendly.
  5. <amp-iframe width="200" height="100" src="https://..." layout="responsive"> </amp-iframe> layout: Responsive Elements 17

    <div class="sixteen-nine"> <iframe width="200" height="100" src="https://..."> </iframe> <div> .sixteen-nine { position: relative; } .sixteen-nine { display: block; content: ""; width: 100%; padding-top: 56.25%; } .sixteen-nine > .content { position: absolute; top: 0; left: 0; right: 0; bottom: 0; } Without AMP With AMP
  6. 18 layout: Responsive Images <amp-img> width="1698" height="2911" layout="responsive" src="/img/narrow.jpg" srcset="/img/wide.jpg

    640w, /img/narrow.jpg 320w" alt="this is a cool image" </amp-img> <img src="/img/image.jpg" width="100%"> <img> Without AMP With AMP
  7. 19

  8. 20

  9. 23 Polyfills import {install as installArrayIncludes} from './polyfills/array-includes'; import {install

    as installDOMTokenListToggle} from './polyfills/domtokenlist-toggle'; import {install as installDocContains} from './polyfills/document-contains'; import {install as installMathSign} from './polyfills/math-sign'; import {install as installObjectAssign} from './polyfills/object-assign'; import {install as installPromise} from './polyfills/promise';
  10. 24

  11. <!-- Define a state called "team" with property "star" -->

    <amp-state id="team"> <script type="application/json"> { "star": "Ronaldo" } </script> </amp-state> 1. STATE
  12. 2. BINDING <!-- Bind text to the expression "'Olá '

    + team.star" --> <p [text]="'Olá ' + team.star"> Olá Ronaldo! </p>
  13. 3. MUTATION <!-- Tap to change the value of team.star.

    --> <button on="tap:AMP.setState({team.star: 'Ronaldinho'})"> Who's that other guy? </button>
  14. <amp-state id="team"> <script type="application/json"> { "star": "Ronaldo" } </script> </amp-state>

    <p [text]="'Olá ' + team.star"> Olá Ronaldo </p> <button on="tap:AMP.setState({team.star: 'Ronaldinho'})"> Say hi to the other guy! </button>
  15. <div class="tooltip" [class]="'tooltip' + (tooltip ? ' tooltip-show' : '')">

    Great price! </div> <amp-date-picker ... on="select:AMP.setState({ tooltip:event.dates.filter(d => d.id == 'deals').length > 0, startDate:event.dates[0], endDate:event.dates[event.dates.length - 1] })"> <template type="amp-mustache" info-template> <span [text]="'You've selected ' + startDate + 'to ' + endDate"> </span> </template> </amp-date-picker>
  16. 36 1 2 3 User discovers content Service Worker installs

    in the background User is instantly upgraded to PWA
  17. <script async src="https://cdn.ampproject.org/shadow-v0.js"></script> <script> function ampReady(callback) { (window.AMP = window.AMP

    || []).push(callback); } ampReady(() => { // things we want to do once AMP is loaded AMP.attachShadowDoc(container, doc, url); }); </script> Shadow AMP
  18. 41

  19. 43

  20. 44

  21. 48

  22. 52