Top Banner
(Brave new world of) HTML5 Chris Mills, Opera Software / Webinale 2011, Berlin, May 31st
98
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: webinale2011_Chris Mills_Brave new world of HTML5Html5

(Brave new world of) HTML5

Chris Mills, Opera Software / Webinale 2011, Berlin, May 31st

Page 2: webinale2011_Chris Mills_Brave new world of HTML5Html5

Open standards evangelist at OperaHTML5 / CSS3 wrangler

dev.opera.comslideshare.net/chrisdavidmills

Education agitator

Also heavy metal drummer

Page 3: webinale2011_Chris Mills_Brave new world of HTML5Html5

...should I use HTML5 today?

Page 4: webinale2011_Chris Mills_Brave new world of HTML5Html5

www.textfiles.com/underconstruction

Page 5: webinale2011_Chris Mills_Brave new world of HTML5Html5

"there is already a lot of excitement for HTML5, but it’s a little too early to deploy it because we’re running into interoperability issues."

Philippe Le Hegaret, W3C interaction domain leader

blogs.techrepublic.com.com/hiner/?p=6369

Page 6: webinale2011_Chris Mills_Brave new world of HTML5Html5

http://www.flickr.com/photos/24374884@N08/4603715307/

Page 7: webinale2011_Chris Mills_Brave new world of HTML5Html5
Page 8: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5…without the hype?

Page 9: webinale2011_Chris Mills_Brave new world of HTML5Html5

A brief history of HTML5

1999 HTML 4.012000 XHTML 1.0

Page 10: webinale2011_Chris Mills_Brave new world of HTML5Html5

2004 W3C focus on XHTML 2.0…the future is XML-based!

http://www.flickr.com/photos/craiga/17071467/

Page 11: webinale2011_Chris Mills_Brave new world of HTML5Html5

WHATWGWeb Hypertext Application Technology Working Group

Page 12: webinale2011_Chris Mills_Brave new world of HTML5Html5

2007 W3C HTML5 WG

Page 13: webinale2011_Chris Mills_Brave new world of HTML5Html5
Page 14: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5 does not replace HTML 4.01 / XHTML 1.0

Page 15: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5 has more bling!

Page 16: webinale2011_Chris Mills_Brave new world of HTML5Html5

“...extending the language to better support Web applications [...] This puts HTML in direct competition with other technologies[...] , in particular Flash and Silverlight.”

Ian Hickson, Editor of HTML5http://lists.w3.org/Archives/Public/public-html/2009Jan/0215.html

Page 17: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML4.01 primarily definedmarkup elements

Page 18: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5 supercedesHTML 4.01, XHTML 1.0and DOM Level 2 HTML

Page 19: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5 adds/redefines markup elements

header, footer, nav, article …

Page 20: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5 extendsDOM Level 2

innerHTML / outerHTML getElementsByClassName()

Page 21: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5 aimed at browser devs

detailed algorithms for processing/error correction

Page 22: webinale2011_Chris Mills_Brave new world of HTML5Html5

1. forms2. multimedia3. web apps

Page 23: webinale2011_Chris Mills_Brave new world of HTML5Html5

1. forms2. multimedia3. web apps

Page 24: webinale2011_Chris Mills_Brave new world of HTML5Html5

improved form elementsbecause the web is more interactive

Page 25: webinale2011_Chris Mills_Brave new world of HTML5Html5

jqueryui.com

Page 26: webinale2011_Chris Mills_Brave new world of HTML5Html5

rich form elements without JavaScript

<input type="date"><input type="time"><input type="month"><input type="week"><input type="datetime" … ><input type="range"><input type="number">

<input type="file" multiple>

<input … autofocus><input … autocomplete>

Page 27: webinale2011_Chris Mills_Brave new world of HTML5Html5

built-in validation without JavaScript<input … required><input type="tel"><input type="email"><input type="url"><input … pattern="[a-z]{3}[0-9]{3}"><input type="number" min="1" max="5">…

Page 28: webinale2011_Chris Mills_Brave new world of HTML5Html5

people.opera.com/patrickl/experiments/forms/newtypes.html

Page 29: webinale2011_Chris Mills_Brave new world of HTML5Html5

people.opera.com/patrickl/experiments/forms/validation.html

Page 30: webinale2011_Chris Mills_Brave new world of HTML5Html5

validity checking with JavaScriptform.checkValidity()formelement.checkValidity()

formelement.setCustomValidity()

formelement.validity

interface ValidityState { readonly attribute boolean valueMissing; readonly attribute boolean typeMismatch; readonly attribute boolean patternMismatch; readonly attribute boolean tooLong; readonly attribute boolean rangeUnderflow; readonly attribute boolean rangeOverflow; readonly attribute boolean stepMismatch; readonly attribute boolean customError; readonly attribute boolean valid;};

Page 31: webinale2011_Chris Mills_Brave new world of HTML5Html5

1. forms2. multimedia3. web apps

Page 32: webinale2011_Chris Mills_Brave new world of HTML5Html5

<bling> ?

Page 33: webinale2011_Chris Mills_Brave new world of HTML5Html5

<video>

Page 34: webinale2011_Chris Mills_Brave new world of HTML5Html5

Adobe Flash currently most commonvideo delivery mechanism

Page 35: webinale2011_Chris Mills_Brave new world of HTML5Html5

<object width="425" height="344"><param name="movie"

value="http://www.youtube.com/v/9sEI1AUFJKw&hl=en&fs=1&"></param>

<param name="allowFullScreen" value="true"></param>

<param name="allowscriptaccess" value="always"></param>

<embed src="http://www.youtube.com/v/9sEI1AUFJKw&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>

Page 36: webinale2011_Chris Mills_Brave new world of HTML5Html5

<video src="video.webm"></video>

Page 37: webinale2011_Chris Mills_Brave new world of HTML5Html5

<video src="video.webm" controls autoplay loop preload="none" poster="poster.jpg" width="320" height="240"> <a href="video.webm">Download movie</a></video>

Page 38: webinale2011_Chris Mills_Brave new world of HTML5Html5

video as native object● behaves like any other HTML element● keyboard accessibility out-of-the-box

Page 39: webinale2011_Chris Mills_Brave new world of HTML5Html5

powerful (simple) API

Page 40: webinale2011_Chris Mills_Brave new world of HTML5Html5

controlling <video> with JavaScript

var v = document.getElementById('player');

v.play();v.pause();v.volume = … ;v.currentTime = … ;…

Page 41: webinale2011_Chris Mills_Brave new world of HTML5Html5

events fired by <video>

var v = document.getElementById('player');

v.addEventListener('loadeddata', function() { … }, true)v.addEventListener('play', function() { … }, true)v.addEventListener('pause', function() { … }, true)v.addEventListener('timeupdate', function() { … }, true)v.addEventListener('ended', function() { … }, true)…

Page 42: webinale2011_Chris Mills_Brave new world of HTML5Html5

people.opera.com/patrickl/experiments/webm/basic-controls

Page 43: webinale2011_Chris Mills_Brave new world of HTML5Html5

people.opera.com/patrickl/experiments/webm/fancy-controls

Page 44: webinale2011_Chris Mills_Brave new world of HTML5Html5

people.opera.com/patrickl/experiments/webm/fancy-swap

Page 45: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5 means all your old dHTML is cool again!

Page 46: webinale2011_Chris Mills_Brave new world of HTML5Html5

video formatsthe big debate?

Page 47: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5 does not specify video container/codec

(same as with images in HTML 4.01)

Page 48: webinale2011_Chris Mills_Brave new world of HTML5Html5

MP4/H.264or

Ogg Theoraor

WebM/VP8

Page 49: webinale2011_Chris Mills_Brave new world of HTML5Html5

MP4 / H.264

ubiquitous, patent encumbered, licensing/royalties

Page 50: webinale2011_Chris Mills_Brave new world of HTML5Html5

Ogg Theora

free and open, no licensing feesnot many tools for it, not web optimised

Page 51: webinale2011_Chris Mills_Brave new world of HTML5Html5

WebM / VP8

open and royalty-free, web-optimisedsupport by hardware and software vendors

Page 52: webinale2011_Chris Mills_Brave new world of HTML5Html5

providing multiple sources<video controls autoplay poster="…" width="…" height="…">

<source src="movie.mp4" type="video/mp4" /><source src="movie.webm" type="video/webm" />

<!-- fallback content --></video>

Page 53: webinale2011_Chris Mills_Brave new world of HTML5Html5

flash fallback for older browsershttp://camendesign.com/code/video_for_everybody

Page 54: webinale2011_Chris Mills_Brave new world of HTML5Html5

<video controls autoplay poster="…" width="…" height="…"><source src="movie.mp4" type="video/mp4" /><source src="movie.webm" type="video/webm" />

<object width="…" height="…" type="application/x-shockwave-flash" data="player.swf">

<param name="movie" value="player.swf" /><param name="flashvars" value=" … file=movie.mp4" /><!-- fallback content -->

</object>

</video>

Page 55: webinale2011_Chris Mills_Brave new world of HTML5Html5

<audio>

Page 56: webinale2011_Chris Mills_Brave new world of HTML5Html5

audio...exactly the same as video

<audio src="music.mp3" controls autoplay … ></audio>

<audio controls autoplay><source src="music.mp3" type="audio/mpeg" /><source src="music.oga" type="audio/ogg" /><!-- fallback content -->

</audio>

formats: MP3 vs Ogg Vorbis (vs WAV)

Page 57: webinale2011_Chris Mills_Brave new world of HTML5Html5

<canvas>

Page 58: webinale2011_Chris Mills_Brave new world of HTML5Html5

canvas = “scriptable images”

<canvas width="…" height="…"></canvas>

Page 59: webinale2011_Chris Mills_Brave new world of HTML5Html5

canvas has standard API methods for drawing

ctx = canvas.getContext("2d");ctx.fillRect(x, y, width, height);ctx.beginPath();ctx.moveTo(x, y);ctx.lineTo(x, y);ctx.bezierCurveTo(x1, y1, x2, y2, c1, c2);

Page 60: webinale2011_Chris Mills_Brave new world of HTML5Html5

people.opera.com/patrickl/experiments/canvas/particle/3

Page 61: webinale2011_Chris Mills_Brave new world of HTML5Html5

mariuswatz.com/works/abstract01js

Page 62: webinale2011_Chris Mills_Brave new world of HTML5Html5

canvas drawing ready-made images

ctx = canvas.getContext("2d");

var logo = new Image();logo.src = 'logo.png';

ctx.drawImage(logo,x1,y1,w1,h1,x2,y2,w2,h2);

or call in an existing image already on the page

Page 63: webinale2011_Chris Mills_Brave new world of HTML5Html5

www.splintered.co.uk/experiments/archives/paranoid_0.3

Page 64: webinale2011_Chris Mills_Brave new world of HTML5Html5

canvas access to image data array

ctx = canvas.getContext("2d");canvasData = ctx.getImageData(x,y,w,h);

[R,G,B,A,R,G,B,A,R,G,B,A,R,G,B,A, … ]

Page 65: webinale2011_Chris Mills_Brave new world of HTML5Html5

github.com/mezzoblue/PaintbrushJS

Page 66: webinale2011_Chris Mills_Brave new world of HTML5Html5

canvas also works with video

ctx = canvas.getContext("2d");v = document.getElementById('player');

ctx.drawImage(v,x1,y1,w1,h2,x2,y2,w2,h2);

grab currently displayed frame (update as appropriate)

Page 67: webinale2011_Chris Mills_Brave new world of HTML5Html5

html5doctor.com/video-canvas-magic

Page 68: webinale2011_Chris Mills_Brave new world of HTML5Html5

www.filamentgroup.com/examples/charting

Page 69: webinale2011_Chris Mills_Brave new world of HTML5Html5

canvas accessibility?

Page 70: webinale2011_Chris Mills_Brave new world of HTML5Html5

video, audio and canvas on any devicewithout plugins

(Java / Flash / Silverlight not ubiquitous)

Page 71: webinale2011_Chris Mills_Brave new world of HTML5Html5
Page 72: webinale2011_Chris Mills_Brave new world of HTML5Html5
Page 73: webinale2011_Chris Mills_Brave new world of HTML5Html5

1. forms2. multimedia3. web apps

Page 74: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5 (and friends) haslots more APIs for developers

(for powerful client-side apps)

Page 75: webinale2011_Chris Mills_Brave new world of HTML5Html5

isgeolocationpartofhtml5.com

Page 76: webinale2011_Chris Mills_Brave new world of HTML5Html5

geolocationnavigator.geolocation.getCurrentPosition(success, error);navigator.geolocation.watchCurrentPosition(success, error);

function success(position) {/* where's Wally? */var lat = position.coords.latitude;var long = position.coords.longitude;...

}

Page 77: webinale2011_Chris Mills_Brave new world of HTML5Html5

application cache<html manifest="blah.manifest">

CACHE MANIFEST# send this with correct text/cache-manifest MIMEimages/sprites.pngscripts/common.jsscripts/jquery.jsstyles/global.css

NETWORK:# never cached (apart from normal caching mechanism)onlineonly.css

FALLBACK:# pattern matching. fallback file will also be cachedimages/ images/not-offline.png

Page 78: webinale2011_Chris Mills_Brave new world of HTML5Html5

data storage

cookies and their limitations...

document.cookie = 'key=value; expires=Thu, 15 Feb 2010 23:59:59 UTC; path=/'…

/* convoluted string operations go here … */

Page 79: webinale2011_Chris Mills_Brave new world of HTML5Html5

localStorage/sessionStoragelocalStorage.setItem(key, value);localStorage.getItem(key);localStorage.clear();localStorage.key = value;if (localStorage.key == '…') { … }…

localStorage – persistent per domainsessionStorage – current URL and window in session

Page 80: webinale2011_Chris Mills_Brave new world of HTML5Html5

WebSQL

relational DB / SQL in browser

var db =openDatabase(dbName, version, displayName, expectedSize);

db.transaction(function(tx) {tx.executeSql(sqlStatement, [], function (tx, result) {

/* do something with the results */});

});

not being developed further (IE/Mozilla prefer IndexedDB) – nonetheless available right now in Opera+WebKit!

Page 81: webinale2011_Chris Mills_Brave new world of HTML5Html5

etcFile API, Web Workers, History API, Web Messaging,Drag and Drop, Server-Sent Events…

Page 82: webinale2011_Chris Mills_Brave new world of HTML5Html5

is it all safe to use, right now?

Page 83: webinale2011_Chris Mills_Brave new world of HTML5Html5

www.youtube.com/html5

Page 84: webinale2011_Chris Mills_Brave new world of HTML5Html5

caniuse.com

Page 85: webinale2011_Chris Mills_Brave new world of HTML5Html5

don't do browser sniffing

http://www.flickr.com/photos/timdorr/2096272747/

Page 86: webinale2011_Chris Mills_Brave new world of HTML5Html5
Page 87: webinale2011_Chris Mills_Brave new world of HTML5Html5

feature-detectionprogressive enhancement, graceful degradation

http://diveintohtml5.org/everything.html

Page 88: webinale2011_Chris Mills_Brave new world of HTML5Html5

modernizr.com

Page 89: webinale2011_Chris Mills_Brave new world of HTML5Html5

patching older browsersgithub.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills

Page 90: webinale2011_Chris Mills_Brave new world of HTML5Html5

yepnopejs.com

Page 91: webinale2011_Chris Mills_Brave new world of HTML5Html5

sublimevideo.net

Page 92: webinale2011_Chris Mills_Brave new world of HTML5Html5

www.happyworm.com/jquery/jplayer

Page 93: webinale2011_Chris Mills_Brave new world of HTML5Html5

HTML5 as Flashkiller?

Page 94: webinale2011_Chris Mills_Brave new world of HTML5Html5

not a question ofHTML5 replacing Flash...

Page 95: webinale2011_Chris Mills_Brave new world of HTML5Html5

giving developers a choice!

Page 96: webinale2011_Chris Mills_Brave new world of HTML5Html5

...should I use HTML5 today?

Page 97: webinale2011_Chris Mills_Brave new world of HTML5Html5

“The future is already here – it's just not very evenly distributed”William Gibson

Page 98: webinale2011_Chris Mills_Brave new world of HTML5Html5

http://[email protected]