SlideShare a Scribd company logo
1 of 40
Download to read offline
AMP for JavaScripters
Implementing Interactive Interfaces with AMP
Weston Ruter & Felix Arntz | #JSforWPConf
Agenda
The AMP Framework
AMP Components
AMP Actions and Events
01
02
03
AMP State and Bindings
AMP Script
04
05
The AMP Framework
AMP is a web component framework to
easily create user-first websites.
AMP is an HTML Framework
Interactivity in AMP
Developers using AMP
AMP Framework Technologies
โ€ข AMP is an open source project.
โ€ข AMP has an open governance model.
โ€ข AMP is built on the open web.
Democratizing Performance
A Minimal AMP Document
<!DOCTYPE html>
<html amp>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="canonical" href="self.html">
<style amp-boilerplate>โ€ฆ</style>
<noscript><style amp-boilerplate>โ€ฆ</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
Hello world.
</body>
</html>
ValidatorWeb Components CDN & Cache
AMP Components
Types of Elements Used in AMP
Built-in
HTML Tags
Optimized
Replacements
Custom
Components
<p> <amp-img> <amp-accordion>
Optimized Replacements
<img> โ†’ <amp-img> / <amp-anim>
<iframe> โ†’ <amp-iframe>
<audio> โ†’ <amp-audio>
<video> โ†’ <amp-video>
Custom Components
Component Example
<amp-carousel>
<amp-carousel type="carousel" ...>
<a class="project-highlight" href="...">
<amp-img src="..." ...></amp-img>
</a>
<!-- ... -->
</amp-carousel>
Component Example
<amp-image-slider>
<amp-image-slider width="300" height="200" layout="responsive">
<amp-img
src="https://upload.wikimedia.org/.../Whole_world_-_land_and_oceans.jpg"
alt="Earth at Day"
layout="fill"></amp-img>
<amp-img
src="https://upload.wikimedia.org/.../City_Lights_2012_-_Flat_map_crop.jpg"
alt="Earth at night"
layout="fill"></amp-img>
</amp-image-slider>
Component Example
<amp-image-lightbox>
<amp-image-lightbox id="lightbox1" layout="nodisplay">
</amp-image-lightbox>
<!-- ... -->
<figure>
<amp-img on="tap:lightbox1.open" role="button" tabindex="0"
src="..." alt="Picture of a dog" width="300" height="246"></amp-img>
<figcaption>Border Collie.</figcaption>
</figure>
<!-- ... -->
Component Example
<amp-list
layout="fixed-height"
height="100"
src="https://blog.amp.dev/wp-json/wp/v2/posts/"
items="."
>
<template type="amp-mustache">
<div>
<a href="{{link}}">{{{title.rendered}}}</a>
</div>
</template>
</amp-list>
<amp-list>
Mobile Menu: amp-sidebar
<button id="toggleNavMenu" on="tap:navMenu.toggle" aria-controls="navMenu">
Toggle Menu
</button>
<amp-sidebar id="navMenu" layout="nodisplay" side="left">
<button id="closeNavMenu" on="tap:navMenu.close">
Close Menu
</button>
<nav>
<ul>
<li><a href="...">...</a></li>
<!-- ... -->
</ul>
</nav>
</amp-sidebar>
AMP Actions and Events
Component API
AMP Events AMP Actions
Triggered by the user. Triggered by an AMP event.
Abstraction of native DOM events. Similar to methods on DOM elements.
on="{event}:{elementId}.{action}[({arg}={value}...)],{event}:{elementId}โ€ฆ"
<button id="toggleNavMenu" on="tap:navMenu.toggle" aria-controls="navMenu">
Toggle Menu
</button>
Global Events and Actions
Events
โ— tap
Actions
โ— show
โ— hide
โ— toggleVisibility
โ— toggleClass
โ— scrollTo
โ— focus
amp.dev/documentation/guides-and-tutorials/learn/amp-actions-and-events
#globally-defined-events-and-actions
Element-Specific Events and Actions
Events
โ— change (<input>)
โ— submit (<form>)
โ— slideChange (<amp-carousel>)
โ— sidebarOpen (<amp-sidebar>)
โ— ...
Actions
โ— submit (<form>)
โ— play (<amp-audio>)
โ— goToSlide (<amp-carousel>)
โ— open (<amp-sidebar>)
โ— ...
amp.dev/documentation/guides-and-tutorials/learn/amp-actions-and-events
#element-specific-events
Mobile Menu: toggleVisibility
<button id="toggleNavMenu" on="tap:navMenu.toggleVisibility" ...>
Toggle Menu
</button>
<nav id="navMenu" hidden>
<ul>
<li><a href="...">...</a></li>
<!-- ... -->
</ul>
</nav>
AMP State and Bindings
โ€ข State
โ€ข Expressions
โ€ข Bindings
amp-bind
<amp-state id="count">
<script type="application/json">0</script>
</amp-state>
Count: <output [text]="count">0</output>
<button on="tap:AMP.setState( { count: count + 1 } )">Increment</button>
Example: Click Counter
<amp-state id="cart">
<script type="application/json">
{ "quantity": 0 }
</script>
</amp-state>
Quantity: <input [value]="cart.quantity" type="number" value="0" readonly>
<button on="tap:AMP.setState( { cart:{ quantity: cart.quantity + 1 } } )">
More
</button>
<button on="tap:AMP.setState( { cart:{ quantity: max( 0, cart.quantity - 1 ) } } )"
disabled [disabled]="cart.quantity == 0">
Less
</button>
Example: Shopping Cart Quantity
<amp-state id="navExpanded">
<script type="application/json">true</script>
</amp-state>
...
<amp-state id="cart">
<script type="application/json">{"quantity":2}</script>
</amp-state>
...
<amp-state id="skus">
<script type="application/json">["123", "456", "789"]</script>
</amp-state>
Multiple amp-state elements
Mobile Menu: amp-bind
<amp-state id="navMenuExpanded">
<script type="application/json">false</script>
</amp-state>
<button id="toggleNavMenu" on="tap:AMP.setState({ navMenuExpanded: ! navMenuExpanded })"
aria-controls="navMenu" aria-expanded="false"
[aria-expanded]="navMenuExpanded ? 'true' : 'false'"
[text]="navMenuExpanded ? 'Close Menu' : 'Open Menu'"
>Open Menu</button>
<nav id="navMenu" hidden [hidden]="!navMenuExpanded">
<ul>
<li><a href="...">...</a></li>
<!-- ... -->
</ul>
</nav>
AMP Script
โ€ข Script runs in Web Worker sandbox
โ€ข WorkerDOM library exposes DOM APIs
โ€ข Built for modern frameworks (e.g. React, Vue)
amp-script
Mobile Menu via amp-script
<amp-script src="https://example.com/.../nav-menu-via-amp-script.js">
<button id="toggleNavMenu" aria-controls="navMenu" aria-expanded="false"
data-open-text="Open Menu" data-close-text="Close Menu"
>Open Menu</button>
<nav id="navMenu" class="hidden">
<ul>
<li><a href="...">...</a></li>
<!-- ... -->
</ul>
</nav>
</amp-script>
const button = document.getElementById( 'toggleNavMenu' );
const navMenu = document.getElementById( 'navMenu' );
button.addEventListener( 'click', () => {
const hidden = ! navMenu.classList.contains( 'hidden' );
navMenu.classList.toggle( 'hidden', hidden );
button.setAttribute( 'aria-expanded', hidden ? 'false' : 'true' );
button.textContent = hidden ? button.getAttribute( 'data-open-text' ) : button.getAttribute( 'data-close-text' );
} );
โ€ข Escape hatch
โ€ข Limit of 150KB
โ€ข Script limited to DOM in scope of container
โ€ข Not all DOM APIs are supported (yet)
amp-script: Restrictions
Canvas Drawing via amp-script
<amp-script src="canvas-drawing-with-amp-script.js" width="400" height="400">
<button>Start drawing!</button>
</amp-script>
Password checker via amp-script
amp.dev/documentation/guides-and-tutorials/develop/
custom-javascript-tutorial
w.org/plugins/amp
AMP
in WordPress
amp.dev
amp-wp.org
Learn More
github.com/westonruter/javascriptforwp-conference-amp-examples
Thank You
Felix Arntz
@felixarntz
Weston Ruter
@westonruter

More Related Content

What's hot

Redirect subdomain to webmail
Redirect subdomain to webmailRedirect subdomain to webmail
Redirect subdomain to webmailKaviyarasu Pugaz
ย 
Get AMP'ed for Accelerated Mobile Pages - SEO Grail Philadelphia 1/20/16
Get AMP'ed for Accelerated Mobile Pages - SEO Grail Philadelphia 1/20/16Get AMP'ed for Accelerated Mobile Pages - SEO Grail Philadelphia 1/20/16
Get AMP'ed for Accelerated Mobile Pages - SEO Grail Philadelphia 1/20/16Sean Malseed
ย 
Accelerated Mobile Pages (AMP) & How it will Impact your Business
Accelerated Mobile Pages (AMP) & How it will Impact your BusinessAccelerated Mobile Pages (AMP) & How it will Impact your Business
Accelerated Mobile Pages (AMP) & How it will Impact your BusinessHarshavardhan MP
ย 
J Query Presentation
J Query PresentationJ Query Presentation
J Query PresentationVishal Kumar
ย 
Accelerated Mobile Pages
Accelerated Mobile PagesAccelerated Mobile Pages
Accelerated Mobile PagesJeremy Green
ย 
V Legakis Presentation
V Legakis PresentationV Legakis Presentation
V Legakis PresentationVLegakis
ย 

What's hot (8)

Redirect subdomain to webmail
Redirect subdomain to webmailRedirect subdomain to webmail
Redirect subdomain to webmail
ย 
Get AMP'ed for Accelerated Mobile Pages - SEO Grail Philadelphia 1/20/16
Get AMP'ed for Accelerated Mobile Pages - SEO Grail Philadelphia 1/20/16Get AMP'ed for Accelerated Mobile Pages - SEO Grail Philadelphia 1/20/16
Get AMP'ed for Accelerated Mobile Pages - SEO Grail Philadelphia 1/20/16
ย 
Accelerated Mobile Pages (AMP) & How it will Impact your Business
Accelerated Mobile Pages (AMP) & How it will Impact your BusinessAccelerated Mobile Pages (AMP) & How it will Impact your Business
Accelerated Mobile Pages (AMP) & How it will Impact your Business
ย 
Ionic by Example
Ionic by ExampleIonic by Example
Ionic by Example
ย 
J Query Presentation
J Query PresentationJ Query Presentation
J Query Presentation
ย 
Accelerated Mobile Pages
Accelerated Mobile PagesAccelerated Mobile Pages
Accelerated Mobile Pages
ย 
V Legakis Presentation
V Legakis PresentationV Legakis Presentation
V Legakis Presentation
ย 
Hyperlink
HyperlinkHyperlink
Hyperlink
ย 

Similar to AMP for JavaScripters

Once Source to Rule Them All
Once Source to Rule Them AllOnce Source to Rule Them All
Once Source to Rule Them AllDavid Yeiser
ย 
Xxx
XxxXxx
Xxxsyfwan
ย 
Accelerated Mobile Pages (AMP) in Magento
Accelerated Mobile Pages (AMP) in MagentoAccelerated Mobile Pages (AMP) in Magento
Accelerated Mobile Pages (AMP) in MagentoMagecom UK Limited
ย 
WPF - An introduction
WPF - An introductionWPF - An introduction
WPF - An introductionSharada Gururaj
ย 
SMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step FunctionsSMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step FunctionsAmazon Web Services
ย 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and ImprovedTimothy Fisher
ย 
Progressive Web Apps: o melhor da Web appficada
Progressive Web Apps: o melhor da Web appficadaProgressive Web Apps: o melhor da Web appficada
Progressive Web Apps: o melhor da Web appficadaCaelum
ย 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCMaarten Balliauw
ย 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with StripesSamuel Santos
ย 
Building iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360FlexBuilding iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360Flexdanielwanja
ย 
Breaking SAP portal (HashDays)
Breaking SAP portal (HashDays)Breaking SAP portal (HashDays)
Breaking SAP portal (HashDays)ERPScan
ย 
Developing Applications for WebOS
Developing Applications for WebOSDeveloping Applications for WebOS
Developing Applications for WebOSChuq Von Rospach
ย 
Course CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsCourse CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsVinรญcius de Moraes
ย 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaJignesh Aakoliya
ย 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014Dariusz Kalbarczyk
ย 
The Future of the Web - Cold Front conference 2016
The Future of the Web - Cold Front conference 2016The Future of the Web - Cold Front conference 2016
The Future of the Web - Cold Front conference 2016Robert Nyman
ย 
Take Your XPages Development to the Next Level
Take Your XPages Development to the Next LevelTake Your XPages Development to the Next Level
Take Your XPages Development to the Next Levelbalassaitis
ย 
URL Hacking 101: An Easy Way to Streamline Processes in Salesforce
URL Hacking 101: An Easy Way to Streamline Processes in Salesforce URL Hacking 101: An Easy Way to Streamline Processes in Salesforce
URL Hacking 101: An Easy Way to Streamline Processes in Salesforce Configero
ย 
Demystifying S-Controls and AJAX
Demystifying S-Controls and AJAXDemystifying S-Controls and AJAX
Demystifying S-Controls and AJAXdreamforce2006
ย 

Similar to AMP for JavaScripters (20)

Once Source to Rule Them All
Once Source to Rule Them AllOnce Source to Rule Them All
Once Source to Rule Them All
ย 
Xxx
XxxXxx
Xxx
ย 
Accelerated Mobile Pages (AMP) in Magento
Accelerated Mobile Pages (AMP) in MagentoAccelerated Mobile Pages (AMP) in Magento
Accelerated Mobile Pages (AMP) in Magento
ย 
WPF - An introduction
WPF - An introductionWPF - An introduction
WPF - An introduction
ย 
SMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step FunctionsSMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step Functions
ย 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
ย 
Progressive Web Apps: o melhor da Web appficada
Progressive Web Apps: o melhor da Web appficadaProgressive Web Apps: o melhor da Web appficada
Progressive Web Apps: o melhor da Web appficada
ย 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
ย 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with Stripes
ย 
Building iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360FlexBuilding iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360Flex
ย 
Breaking SAP portal (HashDays)
Breaking SAP portal (HashDays)Breaking SAP portal (HashDays)
Breaking SAP portal (HashDays)
ย 
Developing Applications for WebOS
Developing Applications for WebOSDeveloping Applications for WebOS
Developing Applications for WebOS
ย 
Course CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsCourse CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.js
ย 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
ย 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014
ย 
The Future of the Web - Cold Front conference 2016
The Future of the Web - Cold Front conference 2016The Future of the Web - Cold Front conference 2016
The Future of the Web - Cold Front conference 2016
ย 
Take Your XPages Development to the Next Level
Take Your XPages Development to the Next LevelTake Your XPages Development to the Next Level
Take Your XPages Development to the Next Level
ย 
Vb.Net Web Forms
Vb.Net  Web FormsVb.Net  Web Forms
Vb.Net Web Forms
ย 
URL Hacking 101: An Easy Way to Streamline Processes in Salesforce
URL Hacking 101: An Easy Way to Streamline Processes in Salesforce URL Hacking 101: An Easy Way to Streamline Processes in Salesforce
URL Hacking 101: An Easy Way to Streamline Processes in Salesforce
ย 
Demystifying S-Controls and AJAX
Demystifying S-Controls and AJAXDemystifying S-Controls and AJAX
Demystifying S-Controls and AJAX
ย 

More from Felix Arntz

Tackling performance in the WordPress ecosystem at scale
Tackling performance in the WordPress ecosystem at scaleTackling performance in the WordPress ecosystem at scale
Tackling performance in the WordPress ecosystem at scaleFelix Arntz
ย 
Enhancing performance in an open-source CMS ecosystem
Enhancing performance in an open-source CMS ecosystemEnhancing performance in an open-source CMS ecosystem
Enhancing performance in an open-source CMS ecosystemFelix Arntz
ย 
The WordPress Performance Team
The WordPress Performance TeamThe WordPress Performance Team
The WordPress Performance TeamFelix Arntz
ย 
Accessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) webAccessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) webFelix Arntz
ย 
Leveraging the Power of Custom Elements in Gutenberg
Leveraging the Power of Custom Elements in GutenbergLeveraging the Power of Custom Elements in Gutenberg
Leveraging the Power of Custom Elements in GutenbergFelix Arntz
ย 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web ComponentsFelix Arntz
ย 
Web Policies & Reporting
Web Policies & ReportingWeb Policies & Reporting
Web Policies & ReportingFelix Arntz
ย 

More from Felix Arntz (7)

Tackling performance in the WordPress ecosystem at scale
Tackling performance in the WordPress ecosystem at scaleTackling performance in the WordPress ecosystem at scale
Tackling performance in the WordPress ecosystem at scale
ย 
Enhancing performance in an open-source CMS ecosystem
Enhancing performance in an open-source CMS ecosystemEnhancing performance in an open-source CMS ecosystem
Enhancing performance in an open-source CMS ecosystem
ย 
The WordPress Performance Team
The WordPress Performance TeamThe WordPress Performance Team
The WordPress Performance Team
ย 
Accessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) webAccessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) web
ย 
Leveraging the Power of Custom Elements in Gutenberg
Leveraging the Power of Custom Elements in GutenbergLeveraging the Power of Custom Elements in Gutenberg
Leveraging the Power of Custom Elements in Gutenberg
ย 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
ย 
Web Policies & Reporting
Web Policies & ReportingWeb Policies & Reporting
Web Policies & Reporting
ย 

Recently uploaded

DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
ย 
โœ‚๏ธ ๐Ÿ‘… Independent Andheri Escorts With Room Vashi Call Girls ๐Ÿ’ƒ 9004004663
โœ‚๏ธ ๐Ÿ‘… Independent Andheri Escorts With Room Vashi Call Girls ๐Ÿ’ƒ 9004004663โœ‚๏ธ ๐Ÿ‘… Independent Andheri Escorts With Room Vashi Call Girls ๐Ÿ’ƒ 9004004663
โœ‚๏ธ ๐Ÿ‘… Independent Andheri Escorts With Room Vashi Call Girls ๐Ÿ’ƒ 9004004663Call Girls Mumbai
ย 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...tanu pandey
ย 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
ย 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
ย 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
ย 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
ย 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
ย 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
ย 
Call Girls In Saket Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Saket Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”Call Girls In Saket Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Saket Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”soniya singh
ย 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
ย 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
ย 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.CarlotaBedoya1
ย 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Lucknow Lucknow best sexual service Online
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Lucknow Lucknow best sexual service OnlineCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Lucknow Lucknow best sexual service Online
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Lucknow Lucknow best sexual service Onlineanilsa9823
ย 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
ย 

Recently uploaded (20)

DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
ย 
โœ‚๏ธ ๐Ÿ‘… Independent Andheri Escorts With Room Vashi Call Girls ๐Ÿ’ƒ 9004004663
โœ‚๏ธ ๐Ÿ‘… Independent Andheri Escorts With Room Vashi Call Girls ๐Ÿ’ƒ 9004004663โœ‚๏ธ ๐Ÿ‘… Independent Andheri Escorts With Room Vashi Call Girls ๐Ÿ’ƒ 9004004663
โœ‚๏ธ ๐Ÿ‘… Independent Andheri Escorts With Room Vashi Call Girls ๐Ÿ’ƒ 9004004663
ย 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
ย 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
ย 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
ย 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
ย 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
ย 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
ย 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
ย 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
ย 
Call Girls In Saket Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Saket Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”Call Girls In Saket Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
Call Girls In Saket Delhi ๐Ÿ’ฏCall Us ๐Ÿ”8264348440๐Ÿ”
ย 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
ย 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
ย 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...
ย 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
ย 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Lucknow Lucknow best sexual service Online
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Lucknow Lucknow best sexual service OnlineCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Lucknow Lucknow best sexual service Online
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Lucknow Lucknow best sexual service Online
ย 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
ย 

AMP for JavaScripters

  • 1. AMP for JavaScripters Implementing Interactive Interfaces with AMP Weston Ruter & Felix Arntz | #JSforWPConf
  • 2. Agenda The AMP Framework AMP Components AMP Actions and Events 01 02 03 AMP State and Bindings AMP Script 04 05
  • 4. AMP is a web component framework to easily create user-first websites.
  • 5. AMP is an HTML Framework
  • 6. Interactivity in AMP Developers using AMP AMP Framework Technologies
  • 7. โ€ข AMP is an open source project. โ€ข AMP has an open governance model. โ€ข AMP is built on the open web. Democratizing Performance
  • 8. A Minimal AMP Document <!DOCTYPE html> <html amp> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <link rel="canonical" href="self.html"> <style amp-boilerplate>โ€ฆ</style> <noscript><style amp-boilerplate>โ€ฆ</style></noscript> <script async src="https://cdn.ampproject.org/v0.js"></script> </head> <body> Hello world. </body> </html>
  • 11. Types of Elements Used in AMP Built-in HTML Tags Optimized Replacements Custom Components <p> <amp-img> <amp-accordion>
  • 12. Optimized Replacements <img> โ†’ <amp-img> / <amp-anim> <iframe> โ†’ <amp-iframe> <audio> โ†’ <amp-audio> <video> โ†’ <amp-video>
  • 14. Component Example <amp-carousel> <amp-carousel type="carousel" ...> <a class="project-highlight" href="..."> <amp-img src="..." ...></amp-img> </a> <!-- ... --> </amp-carousel>
  • 15. Component Example <amp-image-slider> <amp-image-slider width="300" height="200" layout="responsive"> <amp-img src="https://upload.wikimedia.org/.../Whole_world_-_land_and_oceans.jpg" alt="Earth at Day" layout="fill"></amp-img> <amp-img src="https://upload.wikimedia.org/.../City_Lights_2012_-_Flat_map_crop.jpg" alt="Earth at night" layout="fill"></amp-img> </amp-image-slider>
  • 16. Component Example <amp-image-lightbox> <amp-image-lightbox id="lightbox1" layout="nodisplay"> </amp-image-lightbox> <!-- ... --> <figure> <amp-img on="tap:lightbox1.open" role="button" tabindex="0" src="..." alt="Picture of a dog" width="300" height="246"></amp-img> <figcaption>Border Collie.</figcaption> </figure> <!-- ... -->
  • 18. Mobile Menu: amp-sidebar <button id="toggleNavMenu" on="tap:navMenu.toggle" aria-controls="navMenu"> Toggle Menu </button> <amp-sidebar id="navMenu" layout="nodisplay" side="left"> <button id="closeNavMenu" on="tap:navMenu.close"> Close Menu </button> <nav> <ul> <li><a href="...">...</a></li> <!-- ... --> </ul> </nav> </amp-sidebar>
  • 19. AMP Actions and Events
  • 20. Component API AMP Events AMP Actions Triggered by the user. Triggered by an AMP event. Abstraction of native DOM events. Similar to methods on DOM elements. on="{event}:{elementId}.{action}[({arg}={value}...)],{event}:{elementId}โ€ฆ" <button id="toggleNavMenu" on="tap:navMenu.toggle" aria-controls="navMenu"> Toggle Menu </button>
  • 21. Global Events and Actions Events โ— tap Actions โ— show โ— hide โ— toggleVisibility โ— toggleClass โ— scrollTo โ— focus amp.dev/documentation/guides-and-tutorials/learn/amp-actions-and-events #globally-defined-events-and-actions
  • 22. Element-Specific Events and Actions Events โ— change (<input>) โ— submit (<form>) โ— slideChange (<amp-carousel>) โ— sidebarOpen (<amp-sidebar>) โ— ... Actions โ— submit (<form>) โ— play (<amp-audio>) โ— goToSlide (<amp-carousel>) โ— open (<amp-sidebar>) โ— ... amp.dev/documentation/guides-and-tutorials/learn/amp-actions-and-events #element-specific-events
  • 23. Mobile Menu: toggleVisibility <button id="toggleNavMenu" on="tap:navMenu.toggleVisibility" ...> Toggle Menu </button> <nav id="navMenu" hidden> <ul> <li><a href="...">...</a></li> <!-- ... --> </ul> </nav>
  • 24. AMP State and Bindings
  • 26. <amp-state id="count"> <script type="application/json">0</script> </amp-state> Count: <output [text]="count">0</output> <button on="tap:AMP.setState( { count: count + 1 } )">Increment</button> Example: Click Counter
  • 27. <amp-state id="cart"> <script type="application/json"> { "quantity": 0 } </script> </amp-state> Quantity: <input [value]="cart.quantity" type="number" value="0" readonly> <button on="tap:AMP.setState( { cart:{ quantity: cart.quantity + 1 } } )"> More </button> <button on="tap:AMP.setState( { cart:{ quantity: max( 0, cart.quantity - 1 ) } } )" disabled [disabled]="cart.quantity == 0"> Less </button> Example: Shopping Cart Quantity
  • 28. <amp-state id="navExpanded"> <script type="application/json">true</script> </amp-state> ... <amp-state id="cart"> <script type="application/json">{"quantity":2}</script> </amp-state> ... <amp-state id="skus"> <script type="application/json">["123", "456", "789"]</script> </amp-state> Multiple amp-state elements
  • 29. Mobile Menu: amp-bind <amp-state id="navMenuExpanded"> <script type="application/json">false</script> </amp-state> <button id="toggleNavMenu" on="tap:AMP.setState({ navMenuExpanded: ! navMenuExpanded })" aria-controls="navMenu" aria-expanded="false" [aria-expanded]="navMenuExpanded ? 'true' : 'false'" [text]="navMenuExpanded ? 'Close Menu' : 'Open Menu'" >Open Menu</button> <nav id="navMenu" hidden [hidden]="!navMenuExpanded"> <ul> <li><a href="...">...</a></li> <!-- ... --> </ul> </nav>
  • 30.
  • 31.
  • 33. โ€ข Script runs in Web Worker sandbox โ€ข WorkerDOM library exposes DOM APIs โ€ข Built for modern frameworks (e.g. React, Vue) amp-script
  • 34. Mobile Menu via amp-script <amp-script src="https://example.com/.../nav-menu-via-amp-script.js"> <button id="toggleNavMenu" aria-controls="navMenu" aria-expanded="false" data-open-text="Open Menu" data-close-text="Close Menu" >Open Menu</button> <nav id="navMenu" class="hidden"> <ul> <li><a href="...">...</a></li> <!-- ... --> </ul> </nav> </amp-script> const button = document.getElementById( 'toggleNavMenu' ); const navMenu = document.getElementById( 'navMenu' ); button.addEventListener( 'click', () => { const hidden = ! navMenu.classList.contains( 'hidden' ); navMenu.classList.toggle( 'hidden', hidden ); button.setAttribute( 'aria-expanded', hidden ? 'false' : 'true' ); button.textContent = hidden ? button.getAttribute( 'data-open-text' ) : button.getAttribute( 'data-close-text' ); } );
  • 35. โ€ข Escape hatch โ€ข Limit of 150KB โ€ข Script limited to DOM in scope of container โ€ข Not all DOM APIs are supported (yet) amp-script: Restrictions
  • 36. Canvas Drawing via amp-script <amp-script src="canvas-drawing-with-amp-script.js" width="400" height="400"> <button>Start drawing!</button> </amp-script>
  • 37. Password checker via amp-script amp.dev/documentation/guides-and-tutorials/develop/ custom-javascript-tutorial