SlideShare una empresa de Scribd logo
1 de 57
Descargar para leer sin conexión
Doing things better: A more
efficient, usable web?
Chris Mills, :
Who am I?
:
‣ Content lead for MDN (web docs) at
Mozilla
‣ Open web evangelist/hippy
‣ Lover of HTML/CSS/JS
‣ Accessibility whinge bag
‣ Heavy metal drummer
So what are we talking about?
The early days
:
‣ Text
‣ Static
‣ Few form factors
It got better
:
‣ Images AND text!
‣ Dynamic websites
‣ Better, more consistent client-side
tech
‣ Still low power on the client
The modern web is amazing
:
‣ The web on phones, tablets, TVs!
‣ Apps, not pages
‣ The client-side is waaaaay more
complex
Further improvements
:
‣ Efficiency — doing existing things
better
‣ Extensibility — making things more
customizable
‣ Flexibility — allowing the web to
work better across platforms
Streams
A pipe dream…
:
‣ Streaming is nothing new
‣ The browser does it all the time
‣ But why not use it to our advantage?
The Streams API
:
‣ Programatically access streams of
data from the network
‣ Processing chunks one by one
‣ Not having to wait for the whole lot
In addition
:
‣ You can detect when streams start or
end
‣ Cancel streams if required
‣ React to the speed a stream is being
read at
Writing streams
:
‣ You can also write to streams
‣ If you want to modify or generate a
stream to be read somewhere else.
Example
:
// Fetch the original image
fetch('./tortoise.png')
// Retrieve its body as ReadableStream
.then(response => {
const reader = response.body.getReader();
Example
:
return pump();
function pump() {
return reader.read().then(({ done, value }) => {
// When no more data needs to be consumed,
// close the stream
if (done) {
controller.close();
return;
}
// do something with the value here
return pump();
});
}
WebAssembly
Faster code in the browser
:
‣ JavaScript used to be slow
‣ Browser vendors worked hard on this
— V8, SpiderMonkey, etc.
‣ But there is still a limit to how fast JS
can go
A new JavaScript?
:
‣ Some folks from Mozilla came up
with asm.js
‣ A very optimizable subset of JS
‣ And Emscripten, a C++ -> asm.js
compiler
Enter WebAssembly (wasm)
:
‣ A low-level language
‣ Runs in the browser
‣ A compilation target for low-level
languages
Not a JS replacement
:
‣ wasm modules can run alongside JS
‣ Functions can be imported into the
JS runtime
‣ (in the same way as EcmaScript
modules)
Example
:
#include <stdio.h>
int main(int argc, char ** argv) {
printf("Hello Worldn");
}
Example
:
(func $func54 (param $var0 i32) (param
$var1 i32) (param $var2 i32) (result i32)
block (result i32)
i32.const 1
call $import0
i32.const 0
end
)
(func $func55 (param $var0 i32)
i32.const 2
call $import0
)
(data (i32.const 1024)
"0404000005"
Example
:
var importObject = {

imports: { imported_func: arg =>
console.log(arg) }
};
fetch('simple.wasm').then(response =>
response.arrayBuffer()
).then(bytes =>
WebAssembly.instantiate(bytes, importObject)
).then(obj => {
obj.instance.exports.exported_func();
});
Example
:
var importObject = {

imports: { imported_func: arg =>
console.log(arg) }
};
WebAssembly.instantiateStreaming(fetch('simple.wasm'
), importObject)
.then(obj => obj.instance.exports.exported_func());
Web components
Spaghetti code
:
‣ We write a lot of complex HTML
‣ Custom controls, media players, etc.
‣ This makes a mess in our markup
‣ And we risk conflicts
Frameworks do this
:
‣ But their components are locked in
‣ Can’t be transferred
Web components…
:
‣ …allow us to mitigate this
‣ Define custom elements
‣ With encapsulated DOM/style/script
‣ And flexible templates
Custom elements
:
‣ Can be autonomous (stand alone)
‣ Or customized built-ins (extend
existing elements)
Example
:
class EditWord extends HTMLElement {
constructor() {
// Always call super first in constructor
super();
…
}
}
customElements.define('edit-word', EditWord);
<p>My name is <edit-word>Chris</edit-word>.</p>
Example
:
class WordCount extends HTMLParagraphElement {
constructor() {
// Always call super first in constructor
super();
…
}
}
customElements.define('word-count', WordCount,
{ extends: 'p' });
<p is="word-count"></p>
Shadow DOM
:
‣ Already exists in browsers
‣ Think of a <video> element
Shadow DOM
:
‣ You can attach a shadow root to
certain elements
‣ Inside here, you can encapsulate all
your DOM/style/script
Shadow DOM
:
Example
:
// Create a shadow root and a span node
var shadow = this.attachShadow({mode: 'open'});
var text = document.createElement('span');
// Append span to the shadow root
shadow.appendChild(text);
// We want to count words in element's parent
var wcParent = this.parentNode;
// Update word count regularly
setInterval(function() {
var count = 'Words: ' + countWords(wcParent);
text.textContent = count;
}, 200)
Templates
:
‣ <template> is really useful
‣ Store markup now, add it to the DOM
later
‣ Use templates inside a Shadow DOM
Slots
:
‣ <slot> allows you to define a
placeholder
‣ In a template
‣ That you can fill later with whatever
you want
Example
:
<template id="my-paragraph">
<style>
p {
color: white;
background-color: #666;
padding: 5px;
}
</style>
<p><slot name="my-text">My default text</slot></p>
</template>
Example
:
customElements.define('my-paragraph',
class extends HTMLElement {
constructor() {
super();
let template = document.getElementById('my-paragraph');
let templateContent = template.content;
const shadowRoot = this.attachShadow({mode: 'open'})
.appendChild(templateContent.cloneNode(true));
}
})
Example
:
<my-paragraph>
<span slot="my-text">Some text!</span>
</my-paragraph>
Service workers
The offline web?
:
‣ Hrm.
‣ Still doesn’t work very well offline,
does it?
‣ We had AppCache, but that was
proven to be awful
Service workers
:
‣ Chunks of JS that control pages
‣ Registered against pages
‣ Allow you to create custom
responses
Cache API
:
‣ Works with service workers
‣ (Although it doesn’t have to)
‣ Allows you to cache responses
Example
:
if('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/pwa-examples/a2hs/sw.js')
.then(function() { console.log('Service 

Worker Registered');

});
}
Example
:
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open('video-store').then(function(cache) {
return cache.addAll([
'/pwa-examples/a2hs/',
'/pwa-examples/a2hs/index.html',
'/pwa-examples/a2hs/index.js',
'/pwa-examples/a2hs/style.css',
…
]);
})
);
});
Example
:
self.addEventListener('fetch', function(e) {
console.log(e.request.url);
e.respondWith(
caches.match(e.request).then(function(response)
{
return response || fetch(e.request);
})
);
});
SW use cases
:
‣ Offlining web sites using Cache
‣ Client-side compilation
‣ Handling push messages
‣ Custom templating
‣ Background synchronization
‣ On-the-fly polyfilling…
PWAs
Competing with native
:
‣ That age old battle
‣ We’ve largely got tech parity
‣ What we need is UX parity too
The native experience
:
‣ Installing offline
‣ Homescreen icons
‣ Occupying fullscreen
Progressive web apps
:
‣ Provide all of this
‣ While still using the strengths of the
web
Offline
:
‣ Store data offline using IndexedDB,
Web Storage, etc.
‣ Store assets offline using Service
workers + Cache API.
Homescreen/fullscreen
:
‣ Controlled using the web manifest
‣ “Add to homescreen” (A2HS)
supported in Fx/Chrome
Example
:
{

…
"display": "fullscreen",
"icons": [
{
"src": "icon/fox-icon.png",
"sizes": "192x192",
"type": "image/png"
}
],
"name": "Awesome fox pictures",
"short_name": "Foxes",
"start_url": "/pwa-examples/a2hs/index.html"
}
Finished!
Chris Mills, :
cmills@:.com | @chrisdavidmills
Credits
:
‣ Shipping containers photo by Glyn Lowe
‣ Max headroom stolen from a syfy.com article
‣ IE2 image from geek.com
‣ Pipes photo by Matt
‣ Circuit board photo by Phil Norton
‣ Component bricks photo by Sondra
‣ Brain photo by Like_the_Grand_Canyon

Más contenido relacionado

La actualidad más candente

Integrating Node.js with PHP
Integrating Node.js with PHPIntegrating Node.js with PHP
Integrating Node.js with PHP
Lee Boynton
 
Web performance testing with web driver
Web performance testing with web driverWeb performance testing with web driver
Web performance testing with web driver
Michael Klepikov
 
Performance Metrics in a Day with Selenium
Performance Metrics in a Day with SeleniumPerformance Metrics in a Day with Selenium
Performance Metrics in a Day with Selenium
Mark Watson
 

La actualidad más candente (20)

WordPress as a Platform - talk to Bristol Open Source Meetup, 2014-12-08
WordPress as a Platform - talk to Bristol Open Source Meetup, 2014-12-08WordPress as a Platform - talk to Bristol Open Source Meetup, 2014-12-08
WordPress as a Platform - talk to Bristol Open Source Meetup, 2014-12-08
 
ClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScript
 
The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)
 
Integrating Node.js with PHP
Integrating Node.js with PHPIntegrating Node.js with PHP
Integrating Node.js with PHP
 
Power Training DevDays 2009
Power Training DevDays 2009Power Training DevDays 2009
Power Training DevDays 2009
 
Web performance testing with web driver
Web performance testing with web driverWeb performance testing with web driver
Web performance testing with web driver
 
Getting started with node.js
Getting started with node.jsGetting started with node.js
Getting started with node.js
 
Automated Testing with Google Chrome - WebDriver- ChromeDriver
Automated Testing with Google Chrome - WebDriver- ChromeDriverAutomated Testing with Google Chrome - WebDriver- ChromeDriver
Automated Testing with Google Chrome - WebDriver- ChromeDriver
 
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.jsThe MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
 
Intro to go web assembly
Intro to go web assemblyIntro to go web assembly
Intro to go web assembly
 
The MEAN Stack
The MEAN StackThe MEAN Stack
The MEAN Stack
 
Ajax and RJS
Ajax and RJSAjax and RJS
Ajax and RJS
 
The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)
 
Performance Metrics in a Day with Selenium
Performance Metrics in a Day with SeleniumPerformance Metrics in a Day with Selenium
Performance Metrics in a Day with Selenium
 
AWS Community Day - Paul Kuliniewicz - CloudHSM: Frustration as a Service
 AWS Community Day - Paul Kuliniewicz - CloudHSM: Frustration as a Service  AWS Community Day - Paul Kuliniewicz - CloudHSM: Frustration as a Service
AWS Community Day - Paul Kuliniewicz - CloudHSM: Frustration as a Service
 
Node.js with Express
Node.js with ExpressNode.js with Express
Node.js with Express
 
Understanding Page Load / Ziling Zhao (Google)
Understanding Page Load / Ziling Zhao (Google)Understanding Page Load / Ziling Zhao (Google)
Understanding Page Load / Ziling Zhao (Google)
 
The shift to the edge
The shift to the edgeThe shift to the edge
The shift to the edge
 
Pump up the JAM with Gatsby
Pump up the JAM with GatsbyPump up the JAM with Gatsby
Pump up the JAM with Gatsby
 
Wordcamp2009
Wordcamp2009Wordcamp2009
Wordcamp2009
 

Similar a More efficient, usable web

Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar TechnologiesRob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
george.james
 
Rapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 PlatformRapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 Platform
WSO2
 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Look
rumsan
 

Similar a More efficient, usable web (20)

Testable client side_mvc_apps_in_javascript
Testable client side_mvc_apps_in_javascriptTestable client side_mvc_apps_in_javascript
Testable client side_mvc_apps_in_javascript
 
Future of Serverless
Future of ServerlessFuture of Serverless
Future of Serverless
 
Html5 & less css
Html5 & less cssHtml5 & less css
Html5 & less css
 
Treinamento frontend
Treinamento frontendTreinamento frontend
Treinamento frontend
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
 
Always on! Or not?
Always on! Or not?Always on! Or not?
Always on! Or not?
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step Functions
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step Functions
 
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar TechnologiesRob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
 
cross-platform-assets-based-front-end-architecture
cross-platform-assets-based-front-end-architecturecross-platform-assets-based-front-end-architecture
cross-platform-assets-based-front-end-architecture
 
Caching 101
Caching 101Caching 101
Caching 101
 
Angels versus demons: balancing shiny and inclusive
Angels versus demons: balancing shiny and inclusiveAngels versus demons: balancing shiny and inclusive
Angels versus demons: balancing shiny and inclusive
 
Web II - 01 - Introduction to server-side development
Web II - 01 - Introduction to server-side developmentWeb II - 01 - Introduction to server-side development
Web II - 01 - Introduction to server-side development
 
Cache Rules Everything Around Me
Cache Rules Everything Around MeCache Rules Everything Around Me
Cache Rules Everything Around Me
 
Rapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 PlatformRapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 Platform
 
HTML5: A brave new world of markup
HTML5: A brave new world of markupHTML5: A brave new world of markup
HTML5: A brave new world of markup
 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Look
 
Gatsby (Code.Talks) 2019
Gatsby (Code.Talks) 2019Gatsby (Code.Talks) 2019
Gatsby (Code.Talks) 2019
 

Más de Chris Mills

Empowering the "mobile web"
Empowering the "mobile web"Empowering the "mobile web"
Empowering the "mobile web"
Chris Mills
 
Documentation and publishing
Documentation and publishingDocumentation and publishing
Documentation and publishing
Chris Mills
 

Más de Chris Mills (20)

Feedback handling, community wrangling, panhandlin’
Feedback handling, community wrangling, panhandlin’Feedback handling, community wrangling, panhandlin’
Feedback handling, community wrangling, panhandlin’
 
APIs for modern web apps
APIs for modern web appsAPIs for modern web apps
APIs for modern web apps
 
APIs, now and in the future
APIs, now and in the futureAPIs, now and in the future
APIs, now and in the future
 
Guerrilla education
Guerrilla educationGuerrilla education
Guerrilla education
 
Web versus Native: round 1!
Web versus Native: round 1!Web versus Native: round 1!
Web versus Native: round 1!
 
BrazilJS MDN
BrazilJS MDNBrazilJS MDN
BrazilJS MDN
 
Empowering the "mobile web"
Empowering the "mobile web"Empowering the "mobile web"
Empowering the "mobile web"
 
Documentation and publishing
Documentation and publishingDocumentation and publishing
Documentation and publishing
 
MDN is easy!
MDN is easy!MDN is easy!
MDN is easy!
 
Getting rid of images with CSS
Getting rid of images with CSSGetting rid of images with CSS
Getting rid of images with CSS
 
Future layouts
Future layoutsFuture layouts
Future layouts
 
Laying out the future
Laying out the futureLaying out the future
Laying out the future
 
Accessibility doesn't exist
Accessibility doesn't existAccessibility doesn't exist
Accessibility doesn't exist
 
Responsive web design standards?
Responsive web design standards?Responsive web design standards?
Responsive web design standards?
 
Adapt! Media queries and viewport
Adapt! Media queries and viewportAdapt! Media queries and viewport
Adapt! Media queries and viewport
 
Adapt and respond: keeping responsive into the future
Adapt and respond: keeping responsive into the futureAdapt and respond: keeping responsive into the future
Adapt and respond: keeping responsive into the future
 
HTML5 and CSS3: does now really mean now?
HTML5 and CSS3: does now really mean now?HTML5 and CSS3: does now really mean now?
HTML5 and CSS3: does now really mean now?
 
The W3C and the web design ecosystem
The W3C and the web design ecosystemThe W3C and the web design ecosystem
The W3C and the web design ecosystem
 
HTML5 Pearson preso
HTML5 Pearson presoHTML5 Pearson preso
HTML5 Pearson preso
 
Brave new world of HTML5
Brave new world of HTML5Brave new world of HTML5
Brave new world of HTML5
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

More efficient, usable web