HTML5: friend or foe (to Flash)?

162
HTML5 Friend or Foe?

description

A look at how HTML5 aims to plug the holes that Flash has been filling in browsers for the last decade, looking at both HTML5 and non-HTML5 JavaScript APIs.For Flash Brighton in Feb 2010.

Transcript of HTML5: friend or foe (to Flash)?

Page 1: HTML5: friend or foe (to Flash)?

HTML5Friend or Foe?

The Open Web

Page 2: HTML5: friend or foe (to Flash)?

HTML5Friend or Foe?

The Open Web

Page 3: HTML5: friend or foe (to Flash)?

Remy Sharp.Non-Flash-er.

Page 5: HTML5: friend or foe (to Flash)?

"Flash is dead!"

Page 6: HTML5: friend or foe (to Flash)?

Is Flash is dead?

Page 7: HTML5: friend or foe (to Flash)?

Should Flash be worried?

Page 8: HTML5: friend or foe (to Flash)?
Page 9: HTML5: friend or foe (to Flash)?

Video killed the radio Flash star?

Page 11: HTML5: friend or foe (to Flash)?

Flash based

• Capture video

• Encode to FLV

• Upload/create SWF to play FLV

• Copy & paste <object> code

Page 12: HTML5: friend or foe (to Flash)?

Flash based

• Capture video

• Encode to FLV

• Upload/create SWF to play FLV

• Copy & paste <object> code

create

Page 13: HTML5: friend or foe (to Flash)?

Open web based

• Capture video

• Encode to mp4

• Add <video src="foo.mp4" />

Page 14: HTML5: friend or foe (to Flash)?

<video src="dizzy.mp4" />

Page 15: HTML5: friend or foe (to Flash)?

<video src="dizzy.mp4" controls/>

Page 16: HTML5: friend or foe (to Flash)?

<!DOCTYPE html><html lang="en"><head> <meta charset=utf-8 /> <title>Video Example</title></head><body>

</body></html>

<video src="dizzy.mp4" controls/>

Page 17: HTML5: friend or foe (to Flash)?
Page 18: HTML5: friend or foe (to Flash)?

Scripting

Page 19: HTML5: friend or foe (to Flash)?
Page 20: HTML5: friend or foe (to Flash)?

var video = document.getElementsByTagName('video')[0];if (video.paused) { video.play();}

Page 21: HTML5: friend or foe (to Flash)?

var video = document.getElementsByTagName('video')[0];if (video.paused) { video.play();}

// position & asTime defined elsewherevideo.addEventListener('timeupdate', function () { positon.innerHTML = asTime(this.currentTime);}, false);

Page 22: HTML5: friend or foe (to Flash)?

• play(), pause(), canPlayType(t)

API

Page 23: HTML5: friend or foe (to Flash)?

• play(), pause(), canPlayType(t)

• currentTime, paused, duration,

loop, autoplay, muted, volume, etc

API

Page 24: HTML5: friend or foe (to Flash)?

• play(), pause(), canPlayType(t)

• currentTime, paused, duration,

loop, autoplay, muted, volume, etc

• progress, stalled, play, pause,

waiting, canplay, seeking,

timeupdate

API

Page 25: HTML5: friend or foe (to Flash)?

Fullscreen?

Page 26: HTML5: friend or foe (to Flash)?

⚠Warning! User agents should not provide a public API to cause videos to be shown full-screen. A script, combined with a carefully crafted video file, could trick the user into thinking a system-modal dialog had been shown, and prompt the user for a password. There is also the danger of "mere" annoyance, with pages launching full-screen videos when links are clicked or pages navigated. Instead, user-agent specific interface features may be provided to easily allow the user to obtain a full-screen playback mode.

Page 27: HTML5: friend or foe (to Flash)?

⚠Warning! User agents should not provide a public API to cause videos to be shown full-screen. A script, combined with a carefully crafted video file, could trick the user into thinking a system-modal dialog had been shown, and prompt the user for a password. There is also the danger of "mere" annoyance, with pages launching full-screen videos when links are clicked or pages navigated. Instead, user-agent specific interface features may be provided to easily allow the user to obtain a full-screen playback mode.

Page 28: HTML5: friend or foe (to Flash)?
Page 29: HTML5: friend or foe (to Flash)?
Page 30: HTML5: friend or foe (to Flash)?

Pros

Page 31: HTML5: friend or foe (to Flash)?

Pros

• No plugins required

Page 32: HTML5: friend or foe (to Flash)?

Pros

• No plugins required

• Simple API: play(), pause() etc

Page 33: HTML5: friend or foe (to Flash)?

Pros

• No plugins required

• Simple API: play(), pause() etc

• Video & Audio API the same

Page 34: HTML5: friend or foe (to Flash)?

Pros

• No plugins required

• Simple API: play(), pause() etc

• Video & Audio API the same

• Player chrome is HTML & CSS

Page 35: HTML5: friend or foe (to Flash)?

Cons

Page 36: HTML5: friend or foe (to Flash)?

Cons

• Accessibility?

Page 37: HTML5: friend or foe (to Flash)?
Page 38: HTML5: friend or foe (to Flash)?

Cons

• Accessibility?

Page 39: HTML5: friend or foe (to Flash)?

Cons

• Accessibility?

• Codecs

Page 40: HTML5: friend or foe (to Flash)?

Cons

• Accessibility?

• Codecs

• IE

Page 41: HTML5: friend or foe (to Flash)?
Page 42: HTML5: friend or foe (to Flash)?

<video src="dizzy.mp4" controls/>

Page 43: HTML5: friend or foe (to Flash)?

<video controls> <source src="dizzy.ogv" /> <source src="dizzy.mp4" /></video>

Page 44: HTML5: friend or foe (to Flash)?

<video width="640" height="360" poster="dizzy.jpg" controls> <source src="dizzy.ogv" type="video/ogg" /> <source src="dizzy.mp4" type="video/mp4" /><!--[if gt IE 6]> <object width="640" height="375" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"><! [endif]--><!--[if !IE]><!--> <object width="640" height="375" type="video/quicktime" data="dizzy.mp4"> <!--<![endif]--> <param name="src" value="dizzy.mp4" /> <param name="showlogo" value="false" /> <object width="640" height="380" type="application/x-shockwave-flash" data="player.swf?image=dizzy.jpg&amp;file=dizzy.mp4"> <param name="movie" value="player.swf?image=dizzy.jpg&amp;file=dizzy.mp4" /> <img src="dizzy.jpg" width="640" height="360" alt="Title of video" title="No video playback capabilities, please download the video below" /> </object><!--[if gt IE 6]><!--></object><!--<![endif]--></video><p>Download Video: <a href="dizzy.mp4">High Quality "MP4"</a> | <a href="dizzy.ogv">Low Quality "OGG"</a></p>

http://camendesign.com/code/video_for_everybody

Video for Everybody

Page 45: HTML5: friend or foe (to Flash)?

Flash will be needed for video for a while yet.

Page 46: HTML5: friend or foe (to Flash)?

fonts

Page 47: HTML5: friend or foe (to Flash)?

sIFR & Cufon

Page 48: HTML5: friend or foe (to Flash)?
Page 49: HTML5: friend or foe (to Flash)?

• Native font rendering

• IE works via EOT

• Doesn't work in Firefox 3 - 7%

Page 50: HTML5: friend or foe (to Flash)?

StreamingSockets

Page 51: HTML5: friend or foe (to Flash)?
Page 52: HTML5: friend or foe (to Flash)?

• Pushed data relies on Flash

Page 53: HTML5: friend or foe (to Flash)?

• Pushed data relies on Flash

• If no Flash, switches to polling

Page 54: HTML5: friend or foe (to Flash)?

• Pushed data relies on Flash

• If no Flash, switches to polling

• Polling bad for high concurrency

Page 55: HTML5: friend or foe (to Flash)?

• Had to work in corporate environment

• Corp env were blocking odd traffic & Flash

• Needed to be pure JS solution

• It's possible, but complicated

Page 56: HTML5: friend or foe (to Flash)?

WebSocket

Page 57: HTML5: friend or foe (to Flash)?

var ws = new WebSocket("ws://hostname:80/");

ws.onmessage = function (event) { // message in, let's convert it to JSON var data = JSON.parse(event.data);};

ws.onclose = function () {};

ws.onopen = function () {};

Page 58: HTML5: friend or foe (to Flash)?

var ws = new WebSocket("ws://localhost:8080/");ws.onmessage = function(event) { var data = JSON.parse(event.data); var p = $(twitterlib.render(data)); if( $('#tweets > li').length > 15) { $('#tweets >li:last').slideDown(100, function() { $(this).remove(); }); } $('#tweets').prepend(p); p.slideDown(140);};ws.onclose = function() { alert("socket closed");};ws.onopen = function() { //alert("connected...");};

Page 59: HTML5: friend or foe (to Flash)?
Page 60: HTML5: friend or foe (to Flash)?

Graphics

Page 61: HTML5: friend or foe (to Flash)?

2D Graphics

Page 62: HTML5: friend or foe (to Flash)?

Canvas

Page 63: HTML5: friend or foe (to Flash)?
Page 64: HTML5: friend or foe (to Flash)?

Google Analytics - Flash charts

Interactive Demo - Canvas charts

Page 65: HTML5: friend or foe (to Flash)?
Page 66: HTML5: friend or foe (to Flash)?

Let's get technical

Page 67: HTML5: friend or foe (to Flash)?
Page 68: HTML5: friend or foe (to Flash)?

<!DOCTYPE html><html><head> <title>Canvas</title></head><body> <canvas></canvas></body></html>

Page 69: HTML5: friend or foe (to Flash)?

var ctx = canvas.getContext('2d');

Page 70: HTML5: friend or foe (to Flash)?

var ctx = canvas.getContext('2d');

// Create radial gradientvar grad = ctx.createRadialGradient(0,0,0,0,0,600);

Page 71: HTML5: friend or foe (to Flash)?

var ctx = canvas.getContext('2d');

// Create radial gradientvar grad = ctx.createRadialGradient(0,0,0,0,0,600); grad.addColorStop(0, '#E4E4E4');grad.addColorStop(1, '#000');

Page 72: HTML5: friend or foe (to Flash)?

var ctx = canvas.getContext('2d');

// Create radial gradientvar grad = ctx.createRadialGradient(0,0,0,0,0,600); grad.addColorStop(0, '#E4E4E4');grad.addColorStop(1, '#000');

// assign gradients to fillctx.fillStyle = grad;

Page 73: HTML5: friend or foe (to Flash)?

var ctx = canvas.getContext('2d');

// Create radial gradientvar grad = ctx.createRadialGradient(0,0,0,0,0,600); grad.addColorStop(0, '#E4E4E4');grad.addColorStop(1, '#000');

// assign gradients to fillctx.fillStyle = grad; // draw 600x600 fillctx.fillRect(0,0,600,600);

Page 74: HTML5: friend or foe (to Flash)?
Page 75: HTML5: friend or foe (to Flash)?

Let's mix it up

Page 77: HTML5: friend or foe (to Flash)?

body.onmousemove = function (event) { var width = window.innerWidth, height = window.innerHeight, x = event.clientX, y = event.clientY, rx = 600 * x / width, ry = 600 * y / width; var xc = parseInt(256 * x / width); var yc = parseInt(256 * y / height);

grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 600); grad.addColorStop(0, '#000'); grad.addColorStop(1, 'rgb('+xc+','+(255-xc)+','+yc+')');

ctx.fillStyle = grad; ctx.fillRect(0,0,600,600);};

http://html5demos.com/canvas-grad

Page 78: HTML5: friend or foe (to Flash)?

body.onmousemove = function (event) { var width = window.innerWidth, height = window.innerHeight, x = event.clientX, y = event.clientY, rx = 600 * x / width, ry = 600 * y / width; var xc = parseInt(256 * x / width); var yc = parseInt(256 * y / height);

grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 600); grad.addColorStop(0, '#000'); grad.addColorStop(1, 'rgb('+xc+','+(255-xc)+','+yc+')');

ctx.fillStyle = grad; ctx.fillRect(0,0,600,600);};

http://html5demos.com/canvas-grad

Caclulate from the mouse the

radius and colours

Page 79: HTML5: friend or foe (to Flash)?

body.onmousemove = function (event) { var width = window.innerWidth, height = window.innerHeight, x = event.clientX, y = event.clientY, rx = 600 * x / width, ry = 600 * y / width; var xc = parseInt(256 * x / width); var yc = parseInt(256 * y / height);

grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 600); grad.addColorStop(0, '#000'); grad.addColorStop(1, 'rgb('+xc+','+(255-xc)+','+yc+')');

ctx.fillStyle = grad; ctx.fillRect(0,0,600,600);};

http://html5demos.com/canvas-grad

Re-render the gradient

Page 80: HTML5: friend or foe (to Flash)?

body.onmousemove = function (event) { var width = window.innerWidth, height = window.innerHeight, x = event.clientX, y = event.clientY, rx = 600 * x / width, ry = 600 * y / width; var xc = parseInt(256 * x / width); var yc = parseInt(256 * y / height);

grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 600); grad.addColorStop(0, '#000'); grad.addColorStop(1, 'rgb('+xc+','+(255-xc)+','+yc+')');

ctx.fillStyle = grad; ctx.fillRect(0,0,600,600);};

http://html5demos.com/canvas-grad

Set the new fill style and refill -

the browser handles the hard

work

Page 81: HTML5: friend or foe (to Flash)?

body.onmousemove = function (event) { var width = window.innerWidth, height = window.innerHeight, x = event.clientX, y = event.clientY, rx = 600 * x / width, ry = 600 * y / width; var xc = parseInt(256 * x / width); var yc = parseInt(256 * y / height);

grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 600); grad.addColorStop(0, '#000'); grad.addColorStop(1, 'rgb('+xc+','+(255-xc)+','+yc+')');

ctx.fillStyle = grad; ctx.fillRect(0,0,600,600);};

http://html5demos.com/canvas-grad

Page 82: HTML5: friend or foe (to Flash)?

canvas.toDataURL("image/png");

Page 83: HTML5: friend or foe (to Flash)?

canvas.toDataURL("image/png");data:image/png;base64,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

data:image/png;base64,...

Page 84: HTML5: friend or foe (to Flash)?

Canvas+

drawImage+

Video=

Page 85: HTML5: friend or foe (to Flash)?
Page 86: HTML5: friend or foe (to Flash)?
Page 87: HTML5: friend or foe (to Flash)?
Page 89: HTML5: friend or foe (to Flash)?

ctx.translate(canvas.width/2, canvas.height/2);ctx.scale(-1, 1);ctx.translate(-canvas.width/2, -canvas.height/2);

ctx.drawImage( video, 0, 0, video.width, video.height, 0, 0, canvas.width, canvas.height);

http://html5demos.com/video-canvas

Page 90: HTML5: friend or foe (to Flash)?

ctx.translate(canvas.width/2, canvas.height/2);ctx.scale(-1, 1);ctx.translate(-canvas.width/2, -canvas.height/2);

ctx.drawImage( video, 0, 0, video.width, video.height, 0, 0, canvas.width, canvas.height);

http://html5demos.com/video-canvas

Page 91: HTML5: friend or foe (to Flash)?

ctx.getImageData(0, 0, w, h);

Page 92: HTML5: friend or foe (to Flash)?

ctx.getImageData(0, 0, w, h);

0 1 2 3

0 r g b a

1 r g b a

... r g b a

Page 93: HTML5: friend or foe (to Flash)?

pixels.data[i * 4 + 0];

0 1 2 3

0 r g b a

1 r g b a

... r g b a

Page 94: HTML5: friend or foe (to Flash)?

pixels.data[i * 4 + 1];

0 1 2 3

0 r g b a

1 r g b a

... r g b a

Page 95: HTML5: friend or foe (to Flash)?

pixels.data[i * 4 + 2];

0 1 2 3

0 r g b a

1 r g b a

... r g b a

Page 96: HTML5: friend or foe (to Flash)?

pixels.data[i * 4 + 3];

0 1 2 3

0 r g b a

1 r g b a

... r g b a

Page 97: HTML5: friend or foe (to Flash)?

for (i = 0; i < pixels.data.length / 4; i++) { totals.r += pixels.data[i * 4 + 0]; // r totals.g += pixels.data[i * 4 + 1]; // g totals.b += pixels.data[i * 4 + 2]; // b}

var r = parseInt(totals.r / (w*h)), g = parseInt(totals.g / (w*h)), b = parseInt(totals.b / (w*h)), rgb = [r, g, b].join(',');

Page 98: HTML5: friend or foe (to Flash)?
Page 99: HTML5: friend or foe (to Flash)?
Page 100: HTML5: friend or foe (to Flash)?

SVG

Page 101: HTML5: friend or foe (to Flash)?
Page 102: HTML5: friend or foe (to Flash)?
Page 103: HTML5: friend or foe (to Flash)?

...using Flash!

Page 104: HTML5: friend or foe (to Flash)?

segue: just like screaming monkey

Page 105: HTML5: friend or foe (to Flash)?

3D

Page 106: HTML5: friend or foe (to Flash)?

CSSYeah, 3D CSS.

Page 107: HTML5: friend or foe (to Flash)?
Page 108: HTML5: friend or foe (to Flash)?

#canvas { -webkit-perspective: 800; -webkit-perspective-origin: 50% 20em;}

#rubiks { -webkit-transform-style: preserve-3d; -webkit-transform: rotateX(15deg) rotateY(15deg);}

#rubiks .face1 { -webkit-transform: rotateX(90deg) translateZ(10.8em);}

#rubiks .face2 { /* front */ -webkit-transform: translateZ(10.8em);}

#rubiks .face3 { -webkit-transform: rotateY(90deg) translateZ(10.8em);}

#rubiks .face4 { /* back face */ -webkit-transform: rotateY(180deg) translateZ(10.8em);}

#rubiks .face5 { -webkit-transform: rotateY(-90deg) translateZ(10.8em);}

#rubiks .face6 { -webkit-transform: rotateX(-90deg) translateZ(10.8em) rotate(180deg);}

Page 109: HTML5: friend or foe (to Flash)?

WebGL

Page 110: HTML5: friend or foe (to Flash)?
Page 111: HTML5: friend or foe (to Flash)?

Mobile?

Page 112: HTML5: friend or foe (to Flash)?
Page 113: HTML5: friend or foe (to Flash)?

Offline

Page 114: HTML5: friend or foe (to Flash)?

Offline Apps

• Application cache / manifest

• Events: offline, online

• navigator.onLine property

Page 115: HTML5: friend or foe (to Flash)?

Offline Apps

• Application cache / manifest

• Events: offline, online

Page 116: HTML5: friend or foe (to Flash)?

http://icanhaz.com/rubiks

Page 117: HTML5: friend or foe (to Flash)?

http://icanhaz.com/rubiks

Page 118: HTML5: friend or foe (to Flash)?

Using a Manifest

<!DOCTYPE html><html manifest="my.manifest"><body><!-- my page --></body></html>

Page 119: HTML5: friend or foe (to Flash)?

Using a Manifest

<!DOCTYPE html><html manifest="my.manifest"><body><!-- my page --></body></html>

Page 120: HTML5: friend or foe (to Flash)?

CACHE MANIFEST

app.html

css/style.css

js/app.js

#version 13

my.manifest

Page 121: HTML5: friend or foe (to Flash)?

The Manifest

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

text/cache-manifest manifest

Page 122: HTML5: friend or foe (to Flash)?

The Manifest

2. First line must be:

CACHE MANIFEST

Page 123: HTML5: friend or foe (to Flash)?

The Manifest

3. Including page is implicitly included in the cache.

Page 124: HTML5: friend or foe (to Flash)?

The Manifest

4. Two futher namespaces: NETWORK & FALLBACK

FALLBACK:/ offline.html

Page 125: HTML5: friend or foe (to Flash)?

The Manifest

5. Include some versioning to cache bust your manifest

# version 16

Page 126: HTML5: friend or foe (to Flash)?

The process

Page 127: HTML5: friend or foe (to Flash)?

Browser: request Server: serve allBrowser: I have a manifest, cache

assets

Server: serve manifest assets

Browser: applicationCache

updatedBrowser: reload

Browser: serve locally

Browser: only request manifest

file

Server: 304 Not Modified

Page 128: HTML5: friend or foe (to Flash)?

Browser: request Server: serve allBrowser: I have a manifest, cache

assets

Server: serve manifest assets

Browser: applicationCache

updatedBrowser: reload

Browser: serve locally

Browser: only request manifest

file

Server: 304 Not Modified

Page 129: HTML5: friend or foe (to Flash)?

Browser: request Server: serve allBrowser: I have a manifest, cache

assets

Server: serve manifest assets

Browser: applicationCache

updatedBrowser: reload

Browser: serve locally

Browser: only request manifest

file

Server: 304 Not Modified

Page 130: HTML5: friend or foe (to Flash)?

Browser: request Server: serve allBrowser: I have a manifest, cache

assets

Server: serve manifest assets

Browser: applicationCache

updatedBrowser: reload

Browser: serve locally

Browser: only request manifest

file

Server: 304 Not Modified

Page 131: HTML5: friend or foe (to Flash)?

Browser: request Server: serve allBrowser: I have a manifest, cache

assets

Server: serve manifest assets

Browser: applicationCache

updatedBrowser: reload

Browser: serve locally

Browser: only request manifest

file

Server: 304 Not Modified

Page 132: HTML5: friend or foe (to Flash)?

Browser: request Server: serve allBrowser: I have a manifest, cache

assets

Server: serve manifest assets

Browser: applicationCache

updatedBrowser: reload

Browser: serve locally

Browser: only request manifest

file

Server: 304 Not Modified

Page 133: HTML5: friend or foe (to Flash)?

Browser: request Server: serve allBrowser: I have a manifest, cache

assets

Server: serve manifest assets

Browser: applicationCache

updatedBrowser: reload

Browser: serve locally

Browser: only request manifest

file

Server: 304 Not Modified

Page 134: HTML5: friend or foe (to Flash)?

Browser: request Server: serve allBrowser: I have a manifest, cache

assets

Server: serve manifest assets

Browser: applicationCache

updatedBrowser: reload

Browser: serve locally

Browser: only request manifest

file

Server: 304 Not Modified

Page 135: HTML5: friend or foe (to Flash)?

Browser: request Server: serve allBrowser: I have a manifest, cache

assets

Server: serve manifest assets

Browser: applicationCache

updatedBrowser: reload

Browser: serve locally

Browser: only request manifest

file

Server: 304 Not Modified

Page 136: HTML5: friend or foe (to Flash)?

Browser: request Server: serve allBrowser: I have a manifest, cache

assets

Server: serve manifest assets

Browser: applicationCache

updatedBrowser: reload

Browser: serve locally

Browser: only request manifest

file

Server: 304 Not Modified

Problem:Change of contentrequires 2 refreshes

Page 137: HTML5: friend or foe (to Flash)?

applicationCache.onUpdateReady = function () { applicationCache.swapCache(); notice('reload');};

window.onOnline = function () { // fire an update to the cache applicationCache.update();};

Page 138: HTML5: friend or foe (to Flash)?

Web Workers

Page 139: HTML5: friend or foe (to Flash)?

• "Threads"

Page 140: HTML5: friend or foe (to Flash)?

• "Threads"

• Sandboxed

Page 141: HTML5: friend or foe (to Flash)?

• "Threads"

• Sandboxed

•Debugging can be tricky

Page 142: HTML5: friend or foe (to Flash)?
Page 143: HTML5: friend or foe (to Flash)?

http://html5demos.com/worker

Page 144: HTML5: friend or foe (to Flash)?

var w = new Worker('worker.js');

app.html

Page 145: HTML5: friend or foe (to Flash)?

var w = new Worker('worker.js');

w.onmessage = function (event) { alert("msg: " + event.data);};

app.html

Page 146: HTML5: friend or foe (to Flash)?

var w = new Worker('worker.js');

w.onmessage = function (event) { alert("msg: " + event.data);};

w.postMessage('run');

app.html

Page 147: HTML5: friend or foe (to Flash)?

onmessage = function (event) { if (event.data == 'run') { run(); }};

function run() { var n = 1; search: while (running) { n += 1; for (var i = 2; i <= Math.sqrt(n); i += 1) if (n % i == 0) continue search; // found a prime! postMessage(n); }}

worker.js

Page 148: HTML5: friend or foe (to Flash)?

onmessage = function (event) { if (event.data == 'run') { run(); }};

function run() { var n = 1; search: while (running) { n += 1; for (var i = 2; i <= Math.sqrt(n); i += 1) if (n % i == 0) continue search; // found a prime! postMessage(n); }}

worker.js

Page 149: HTML5: friend or foe (to Flash)?

onmessage = function (event) { if (event.data == 'run') { run(); }};

function run() { var n = 1; search: while (running) { n += 1; for (var i = 2; i <= Math.sqrt(n); i += 1) if (n % i == 0) continue search; // found a prime! postMessage(n); }}

worker.js

Page 150: HTML5: friend or foe (to Flash)?

Can dos

• Spawn more workers

• setTimeout/Interval & clear

• Access navigator

• Error handling onerror

• XHR (though responseXML is null)

Page 151: HTML5: friend or foe (to Flash)?

8 workers Workers disabled

Page 152: HTML5: friend or foe (to Flash)?

8 workers Workers disabled

Page 153: HTML5: friend or foe (to Flash)?

Geolocation

Page 154: HTML5: friend or foe (to Flash)?
Page 155: HTML5: friend or foe (to Flash)?

Not always accurate!

Page 156: HTML5: friend or foe (to Flash)?

navigator.geolocation.getCurrentPosition(function (geo) { console.log(geo);}, function () { // error handler});

Page 157: HTML5: friend or foe (to Flash)?

navigator.geolocation.getCurrentPosition(function (geo) { console.log(geo);}, function () { // error handler});

Page 158: HTML5: friend or foe (to Flash)?
Page 159: HTML5: friend or foe (to Flash)?
Page 160: HTML5: friend or foe (to Flash)?

Microdata, datagrids, XHR2 & upload progress events

History manager, drag & drop

AccessibleRichInternetApplications

...and more!