SlideShare a Scribd company logo
HTML5
Huh, What is it good for?
Remy Sharp
@rem

  Plug: Introducing HTML5
It's more than
๏ HTML        ๏ Buzzword
๏ New HTML5   ๏ Simple
  elements      doctype
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
                          <!doctype html>
  <title>My HTML5 page</title>
  <style>
  body {

  }
                         <style> <script>
    font-family: sans-serif;

  </style>
</head>
<body>
<article>
  <h1>My story</h1>               <article>
  <p>With JavaScript</p>
</article>
<script src="funky.js"></script>
<script>
makeFunky(document.querySelector('article'));
</script>
</body>
</html>
JavaScript
๏Offline
๏App   cache

๏WebStorage
๏WebSQL
๏IndexedDB
๏Multimedia
๏Video    & Audio
๏X-domain




                     JavaScript
  messaging

๏CORS
๏File    API

๏Drag    & Drop

๏History       API

๏Lots,    lots
 more.
JavaScript
๏ Drawing
๏ Offline
๏ URLs
๏ Real-time
When can I
use "HTML5"?
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
Making it
work in
the "other"
browser
Polyfills
will/might save you
A shim that mimics a future
API providing a fallback to
       older browsers
    http://goo.gl/0Z9eI
Tools
Modernizr to detect support
yepnode.js to conditionally load
(available as part of Modernizr)
Tools
Modernizr.load({
  test: Modernizr.geolocation,
  nope: 'geo-polyfill.js',
  complete: initMyGeoApp
});
Oh, and learn
JavaScript
Canvas
Han Solo of HTML5
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Canvas</title>
</head>
<body>
  <canvas></canvas>
</body>
</html>
2D API
ctx = canvas.getContext('2d')
HTML5: huh, what is it good for?
๏Gradients
๏Pixel manipulation
๏Paths
๏Shadows
๏Export to data url
๏State saving
Gradients
Gradients
var rainbow = ctx.createLinearGradient(0, 0, w, h),
    colours = {
       0: 'red',
       0.167: 'orange',
       0.333: 'yellow',
       // etc
    };

for (var key in colours) {
  rainbow.addColorStop(key, colours[key]);
}

ctx.fillStyle = rainbow;
ctx.fillRect(0, 0, w, h);
Pixel Pushing
Pixel Pushing
var pixels = ctx.getImageData(0, 0, w, h),
    len = pixels.data.length;

for (var i = 0; i < len; i += 4) {
  var rgb = 'rgb(' + // ↵
    [
      pixels.data[i],   // red
      pixels.data[i+1], // green
      pixels.data[i+2] // blue
    ].join(',') + ')';
}
Shadows & Paths
Shadows
ctx.shadowBlur = 2;
ctx.shadowOffsetX = 2;
ctx.shadowOffsetY = 2;
ctx.shadowColor = 'rgba(0,0,0,.7)';
Paths
var pinsize = 26,
    pinedge = pinsize * 0.1,
    centre = pinsize/2,
    radius = centre - pinedge,
    circle = Math.PI * 2;

ctx.fillStyle = rgb; // from our pixel
ctx.beginPath();
ctx.arc(centre, centre, // ↵
        radius, 0, circle, true);
ctx.closePath();
ctx.fill();
HTML5: huh, what is it good for?
Export
ctx.canvas.toDataURL('image/png')



data:image/png;base64,...
T ip
  context.canvas

  All context contain back-
  reference to it's canvas
State Saving
pinctx.fillStyle = '#fff';
pinctx.save();
pinctx.fillStyle = '#f00';
// do something
pinctx.restore();
// now fillStyle is #fff
HTML5: huh, what is it good for?
Offline Applications
Using a Manifest
<!DOCTYPE html>
<html manifest="my.appcache">
<body>
<!-- my page -->
</body>
</html>
my.appcache
CACHE MANIFEST
app.html
css/style.css
js/app.js
#version 13
The Manifest

1. Serve as text/manifest, by
   adding to mime.types:

text/cache-manifest appcache
Firefox caching

<IfModule mod_expires.c>
 ExpiresActive on
 ExpiresByType text/cache-manifest
↪ “access plus 0 seconds”
</IfModule>
The Manifest

2. First line must be:

     CACHE MANIFEST
The Manifest

3. Including page is implicitly
   included in the cache.
The Manifest

4. Two futher namespaces:
   NETWORK & FALLBACK
CACHE MANIFEST

CACHE:
app.js
app.css
index.html

NETWORK:
http://*
https://*

FALLBACK:
/ offline.html
CACHE MANIFEST


What to   CACHE:
          app.js

cache
          app.css
          index.html

          NETWORK:
          http://*
          https://*

          FALLBACK:
          / offline.html
CACHE MANIFEST

                 CACHE:
App cache        app.js
                 app.css
requires all     index.html


resources are    NETWORK:
                 http://*

accounted for.   https://*

                 FALLBACK:
                 / offline.html
CACHE MANIFEST

                  CACHE:
                  app.js
Requests for      app.css

files not found   index.html

in the cache,     NETWORK:
                  http://*
are directed      https://*

to offline.html   FALLBACK:
(when offline).   / offline.html
CACHE MANIFEST

CACHE:
app.js
app.css
index.html

NETWORK:
http://*
https://*

FALLBACK:
/ offline.html
The Manifest

5. Include some versioning to
   cache bust your manifest

      # version 16
HTML5: huh, what is it good for?
When your app updates

applicationCache.onUpdateReady = function () {
   if (confirm("New version ready. Refresh?")) {
     // reload
     window.location = window.location;
   }
};
T ip
   Do offline last
Web Storage
     http://www.flickr.com/photos/ph0t0s/64821154
Key / Value pair
๏ localStorage, persistent
๏ sessionStorage, temporary
๏ Extremely simple to use
๏ Storage events
sessionStorage.name = '@rem';

// page is reloaded
var name = sessionStorage.name;
if (name !== undefined) {
  alert('Welcome back ' + name);
}
sessionStorage.name = '@rem';

// page is reloaded
var name = sessionStorage.name;
if (name !== undefined) {
  alert('Welcome back ' + name);
}
sessionStorage.name = '@rem';

// page is reloaded
var name = sessionStorage.name;
if (name !== undefined) {
  alert('Welcome back ' + name);
}
Storage
coerces to
String
String
var sess = sessionStorage;

sess.data = JSON.stringify(data);
String
var sess = sessionStorage;

sess.data = JSON.stringify(data);

var data = JSON.parse(
   sess.data || '{}' // or empty obj
);
Events
window.onstorage = function(e){
   // e.key
   // e.newValue
   // e.oldValue
   // e.url
};
HTML5: huh, what is it good for?
URLs
HTML5: huh, what is it good for?
History API
history.pushState(obj, title, url);

window.onpopstate = fn;
Detection
!!(window.history	
  &&	
  
history.pushState)
Polyfill
History.js
https://github.com/balupton/history.js
hashchange
window.onhashchange = function(e) {
   // user went back or forward
   // now read location.hash
};
Server Sent
Events
"push based XHR"
Prerequisites
๏ Persistent connection support
   (event based are favourable: ie. node, twisted, etc)


๏ Support in browser* but we can fix that :)
๏ If not native, fails over to polling
Limitations
๏ Same origin rules
๏ No support in Firefox or IE
๏ Read only
Usage
var es = new EventSource(url);

es.onopen = function () {
   console.log('open stream');
};

es.onmessage = function (event) {
   console.log('got message: ' + event.data);
};
Server code
app.get('/sse', function (req, res) {
  connections.push(res);

  res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache'
  });
  res.write('eventId:0nn');
});


                          Using Connect
Server code
connections.forEach(function (c) {
  c.write('data:' + JSON.stringify(req.body) + 'nn');
});



                        req.body is an object of key/values
HTML5: huh, what is it good for?
Web Sockets
Two way real-time comms




           http://www.flickr.com/photos/44442915@N00/4960579336
In a nutshell
๏Persistent connection
๏Tiny chunks of data exchanged
๏Bi-directional & no origin rules
Some Uses
๏Chat / "hello world"
๏Streaming data like stock share prices
๏Multi-player game state
๏Google Wave   remember? :)
Native or
polyfilled
  IE6✓ :'(
http://github.com/gimite/web-socket-js/
var url = 'ws://node.remysharp.com:8000',
       conn = new WebSocket(url);


conn.onopen = function () {
     conn.send('@rem says Hi!');
};


conn.onmessage = function (event) {
     console.log(event.data);
};
var url = 'ws://node.remysharp.com:8000',
       conn = new WebSocket(url);


conn.onopen = function () {
     conn.send('@rem says Hi!');
};


conn.onmessage = function (event) {
     console.log(event.data);
};
var url = 'ws://node.remysharp.com:8000',
       conn = new WebSocket(url);


conn.onopen = function () {
     conn.send('@rem says Hi!');
};


conn.onmessage = function (event) {
     console.log(event.data);
};
var url = 'ws://node.remysharp.com:8000',
       conn = new WebSocket(url);


conn.onopen = function () {
     conn.send('@rem says Hi!');
};


conn.onmessage = function (event) {
     console.log(event.data);
};
var url = 'ws://node.remysharp.com:8000',
       conn = new WebSocket(url);


conn.onopen = function () {
     conn.send('@rem says Hi!');
};


conn.onmessage = function (event) {
     console.log(event.data);
};
var url = 'ws://node.remysharp.com:8000',
       conn = new WebSocket(url);


conn.onopen = function () {
     conn.send('@rem says Hi!');
};


conn.onmessage = function (event) {
     console.log(event.data);
};
var url = 'ws://node.remysharp.com:8000',
       conn = new WebSocket(url);


conn.onopen = function () {
     conn.send('@rem says Hi!');
};


conn.onmessage = function (event) {
     console.log(event.data);
};
Demo
jsbin.com/uwomu6
Questions?
@rem
remy@leftlogic.com

More Related Content

What's hot (20)

PPTX
Installation Openstack Swift
ymtech
 
PDF
CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021
whywaita
 
PDF
Keybase Vault Auto-Unseal HashiTalks2020
Bas Meijer
 
PPTX
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Yevgeniy Brikman
 
PDF
Kubernetes on AWS
Grant Ellis
 
PDF
Istio By Example (extended version)
Josef Adersberger
 
PDF
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
NAVER D2
 
PDF
Varnish http accelerator
no no
 
PPTX
Microservices with SenecaJS (part 2)
Designveloper
 
ODP
Continuous Security
Sysdig
 
PDF
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
謝 宗穎
 
PDF
Varnish - PLNOG 4
Leszek Urbanski
 
PPTX
Cluster Lifecycle Landscape
Mike Danese
 
PDF
AWS Black Belt Online Seminar AWS CloudFormation アップデート
Amazon Web Services Japan
 
PDF
Cluster Networking with Docker
Stefan Schimanski
 
PDF
Securing Containers - Sathyajit Bhat - Adobe - Container Conference 18
CodeOps Technologies LLP
 
ODP
Dynamic Languages Web Frameworks Indicthreads 2009
Arun Gupta
 
PPTX
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
HubSpot Product Team
 
PDF
IBM Monitoring and Diagnostic Tools - GCMV 2.8
Chris Bailey
 
PDF
Ruby on microsoft azure april 2014
Brian Benz
 
Installation Openstack Swift
ymtech
 
CyberAgent における OSS の CI/CD 基盤開発 myshoes #CICD2021
whywaita
 
Keybase Vault Auto-Unseal HashiTalks2020
Bas Meijer
 
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Yevgeniy Brikman
 
Kubernetes on AWS
Grant Ellis
 
Istio By Example (extended version)
Josef Adersberger
 
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
NAVER D2
 
Varnish http accelerator
no no
 
Microservices with SenecaJS (part 2)
Designveloper
 
Continuous Security
Sysdig
 
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
謝 宗穎
 
Varnish - PLNOG 4
Leszek Urbanski
 
Cluster Lifecycle Landscape
Mike Danese
 
AWS Black Belt Online Seminar AWS CloudFormation アップデート
Amazon Web Services Japan
 
Cluster Networking with Docker
Stefan Schimanski
 
Securing Containers - Sathyajit Bhat - Adobe - Container Conference 18
CodeOps Technologies LLP
 
Dynamic Languages Web Frameworks Indicthreads 2009
Arun Gupta
 
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
HubSpot Product Team
 
IBM Monitoring and Diagnostic Tools - GCMV 2.8
Chris Bailey
 
Ruby on microsoft azure april 2014
Brian Benz
 

Similar to HTML5: huh, what is it good for? (20)

PDF
HTML5 tutorial: canvas, offfline & sockets
Remy Sharp
 
PPTX
HTML5 on Mobile
Adam Lu
 
PDF
Front-end. Global domination
Stfalcon Meetups
 
PDF
Frontend. Global domination.
Андрей Вандакуров
 
PDF
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
Robert Nyman
 
PDF
HTML5 New Features and Resources
Ron Reiter
 
PDF
The Mobile Web - HTML5 on mobile devices
Wesley Hales
 
PDF
Html5 and beyond the next generation of mobile web applications - Touch Tou...
RIA RUI Society
 
PDF
Pushing the Web: Interesting things to Know
n|u - The Open Security Community
 
KEY
Optimization of modern web applications
Eugene Lazutkin
 
PDF
Real Time Web with Node
Tim Caswell
 
PDF
Building great mobile apps: Somethings you might want to know
shwetank
 
PDF
Offline of web applications
FDConf
 
PDF
Offline for web - Frontend Dev Conf Minsk 2014
Jan Jongboom
 
PPTX
Html5
Zahin Omar Alwa
 
PDF
APIs for modern web apps
Chris Mills
 
PDF
APIs, now and in the future
Chris Mills
 
PDF
HTML5 JS APIs
Remy Sharp
 
PPTX
Html5 and web technology update
Doug Domeny
 
KEY
HTML5와 모바일
ACCESS
 
HTML5 tutorial: canvas, offfline & sockets
Remy Sharp
 
HTML5 on Mobile
Adam Lu
 
Front-end. Global domination
Stfalcon Meetups
 
Frontend. Global domination.
Андрей Вандакуров
 
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
Robert Nyman
 
HTML5 New Features and Resources
Ron Reiter
 
The Mobile Web - HTML5 on mobile devices
Wesley Hales
 
Html5 and beyond the next generation of mobile web applications - Touch Tou...
RIA RUI Society
 
Pushing the Web: Interesting things to Know
n|u - The Open Security Community
 
Optimization of modern web applications
Eugene Lazutkin
 
Real Time Web with Node
Tim Caswell
 
Building great mobile apps: Somethings you might want to know
shwetank
 
Offline of web applications
FDConf
 
Offline for web - Frontend Dev Conf Minsk 2014
Jan Jongboom
 
APIs for modern web apps
Chris Mills
 
APIs, now and in the future
Chris Mills
 
HTML5 JS APIs
Remy Sharp
 
Html5 and web technology update
Doug Domeny
 
HTML5와 모바일
ACCESS
 
Ad

More from Remy Sharp (20)

PDF
HTML5: where flash isn't needed anymore
Remy Sharp
 
PDF
Yearning jQuery
Remy Sharp
 
PDF
Is HTML5 Ready? (workshop)
Remy Sharp
 
PDF
Forget the Web
Remy Sharp
 
PDF
Interaction Implementation
Remy Sharp
 
PDF
jQuery: out with the old, in with the new
Remy Sharp
 
PDF
Developing for Mobile
Remy Sharp
 
PDF
Browsers with Wings
Remy Sharp
 
PDF
Webapps without the web
Remy Sharp
 
PDF
TwitterLib.js
Remy Sharp
 
PDF
HTML5: friend or foe (to Flash)?
Remy Sharp
 
PDF
codebits 2009 HTML5 JS APIs
Remy Sharp
 
PDF
HTML5 JavaScript APIs
Remy Sharp
 
PDF
iPhone Appleless Apps
Remy Sharp
 
PDF
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
PDF
Write Less Do More
Remy Sharp
 
PDF
HTML5 & Friends
Remy Sharp
 
PDF
jQuery Loves Developers - SWDC2009
Remy Sharp
 
PDF
DOM Scripting Toolkit - jQuery
Remy Sharp
 
PDF
Prototype & jQuery
Remy Sharp
 
HTML5: where flash isn't needed anymore
Remy Sharp
 
Yearning jQuery
Remy Sharp
 
Is HTML5 Ready? (workshop)
Remy Sharp
 
Forget the Web
Remy Sharp
 
Interaction Implementation
Remy Sharp
 
jQuery: out with the old, in with the new
Remy Sharp
 
Developing for Mobile
Remy Sharp
 
Browsers with Wings
Remy Sharp
 
Webapps without the web
Remy Sharp
 
TwitterLib.js
Remy Sharp
 
HTML5: friend or foe (to Flash)?
Remy Sharp
 
codebits 2009 HTML5 JS APIs
Remy Sharp
 
HTML5 JavaScript APIs
Remy Sharp
 
iPhone Appleless Apps
Remy Sharp
 
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
Write Less Do More
Remy Sharp
 
HTML5 & Friends
Remy Sharp
 
jQuery Loves Developers - SWDC2009
Remy Sharp
 
DOM Scripting Toolkit - jQuery
Remy Sharp
 
Prototype & jQuery
Remy Sharp
 
Ad

Recently uploaded (20)

PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
July Patch Tuesday
Ivanti
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 

HTML5: huh, what is it good for?