using html5 sensibly

74
Using HTML5 sensibly Christian Heilmann, London Ajax User Meetup, February 2011

Upload: christian-heilmann

Post on 20-Jan-2015

16.992 views

Category:

Technology


1 download

DESCRIPTION

HTML5 is hot right now and a lot is being said about it. It is time to take a look at what it means to apply it on the web and see how things work out. Turns out we still have a lot to fix and we need your help.

TRANSCRIPT

Page 1: Using HTML5 sensibly

Using HTML5 sensibly

Christian Heilmann, London Ajax User Meetup, February 2011

Page 2: Using HTML5 sensibly

This will be a change from my normal talks.

Instead of giving you the facts, it is my turn to ask some questions.

Page 3: Using HTML5 sensibly

But first, let me tell you a story. As stories are important!

Page 4: Using HTML5 sensibly

Back in 1939...

...Antarctica needed exploring

Page 5: Using HTML5 sensibly

The Antarctic Explorer

Page 6: Using HTML5 sensibly
Page 7: Using HTML5 sensibly
Page 8: Using HTML5 sensibly
Page 9: Using HTML5 sensibly

So let’s see what went wrong there...

★ Purely engineering driven★ Tested while on the road★ Never tested in the real

environment★ Massive media excitement before

it proved its worth

Page 10: Using HTML5 sensibly
Page 11: Using HTML5 sensibly

HTML5 is the new hotness!

Page 12: Using HTML5 sensibly

http://studio.html5rocks.com/

Page 13: Using HTML5 sensibly

http://www.apple.com/html5/

Page 15: Using HTML5 sensibly

Everything is HTML5 - including browser specific tricks.

Page 16: Using HTML5 sensibly

To a degree this is understandable.

There is a lot of confusion about the players and the specs.

Page 17: Using HTML5 sensibly

Markup

Stuff for Browser/Parser developers

HTML(5)

JavaScript APIsgeneral WTF

Page 18: Using HTML5 sensibly

This gives people lots of space for interpretation and focus - and the opportunity to rant.

Page 19: Using HTML5 sensibly

The main premise of HTML5 is pragmatism -making things simpler for all of us.

Page 20: Using HTML5 sensibly

Another big topic is that XML was just not for the web - end users should not suffer for the errors of the authors.

Page 21: Using HTML5 sensibly

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>HTML - c'est moi!</title> <link rel="stylesheet" type="text/css" href="styles.css"> <script type="text/javascript" src="magic.js"> </script></head><body> <h1>Heading! Everybody duck!</h1> <p>I am content, hear me roar!</p> <p class="footer">By me!</p></body></html>

Page 22: Using HTML5 sensibly

<!DOCTYPE html> <html lang="en"><head> <meta charset="utf-8"> <title>HTML5, c'est moi, ou HTML...</title> <link rel="stylesheet" href="styles.css"> <script src="magic.js"></script></head><body> <h1>Heading! Everybody duck!</h1> <p>I am content, hear me roar!</p> <p class="footer">By me!</p></body></html>

Page 23: Using HTML5 sensibly

HTML5 also includes new semantic elements (based on class names in use) that structure our documents much better than before.

Page 24: Using HTML5 sensibly

<!DOCTYPE html> <html lang="en"><head> <title>HTML5, c'est moi, ou HTML...</title> <link rel="stylesheet" href="styles.css"> <script src="magic.js"></script></head><body> <header><h1>Heading! Everybody duck!</h1></header> <section> <p>I am content, hear me roar!</p> </section> <footer><p>By me!</p></footer></body></html>

Page 25: Using HTML5 sensibly

HTML5 defines and expects browsers to fix omissions for us - and doesn’t mind case or quotes.

Page 26: Using HTML5 sensibly

<!DOCTYPE html> <html lang=en> <TITLE>HTML5, c'est moi, ou HTML...</title> <LINK rel=stylesheet href=styles.css> <script src=magic.js></SCRIPT><body> <HEADER><h1>Heading! Everybody duck!</h1></header> <section> <p>I am content, hear me roar!</p> </SECTION> <footer><p>By me!</p></FOOTER></body></HTML>

Page 27: Using HTML5 sensibly

The reason is that browsers do that anyways - just check the generated code of a document like that.

Page 28: Using HTML5 sensibly

<!DOCTYPE html> <html lang="en"><head> <title>HTML5, c'est moi, ou HTML...</title> <link rel="stylesheet" href="styles.css"> <script src="magic.js"></script> </head><body> <header><h1>Heading! Everybody duck!</h1></header> <section> <p>I am content, hear me roar!</p>

</section> <footer><p>By me!</p></footer></body></html>

Page 29: Using HTML5 sensibly

<!DOCTYPE html> <html lang=en> <TITLE>HTML5, c'est moi, ou HTML...</title> <LINK rel=stylesheet href=styles.css> <script src=magic.js></SCRIPT><body> <HEADER><h1>Heading! Everybody duck!</h1></header> <section> <p>I am content, hear me roar! </SECTION> <footer><p>By me!</p></FOOTER></body></HTML>

</p>

Page 30: Using HTML5 sensibly

<!DOCTYPE html><html lang="en"><head> <title>HTML5, c'est moi, ou HTML...</title> <link rel="stylesheet" href="styles.css"> <script src="magic.js"></script></head><body> <header><h1>Heading! Everybody duck!</h1></header> <section> <p>I am content, hear me roar! <footer></footer> </p> <p>By me!</p> </section></body></html>

Page 31: Using HTML5 sensibly

Browsers fix a lot of stuff for us, this has always been the case.

Page 32: Using HTML5 sensibly

?Can innovation be based on “people never did this correctly anyways”?

Page 33: Using HTML5 sensibly

?Is it HTML or BML?

Page 34: Using HTML5 sensibly

?Should HTML be there only for browsers?

What about conversion Services? Search bots? Content scrapers?

Page 35: Using HTML5 sensibly

Internet Explorer 6

Page 36: Using HTML5 sensibly

Internet Explorer doesn’t allow styling for elements it doesn’t understand as part of HTML.

Page 37: Using HTML5 sensibly

HTML is the thing we base everything on - so if we exclusively use the new HTML5 elements, we give IE unstyled documents.

Page 38: Using HTML5 sensibly

Time to applysome fixes!

Page 39: Using HTML5 sensibly

First fix - elements created with JS can be styled in IE. <!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <style>header{color:#fff;background:#369;}</style> <script>document.createElement('header');</script></head><body> <header><h1>Hello!</h1></header></body></html>

Page 40: Using HTML5 sensibly

Remy Sharp packaged that up nicely in HTML5shiv.

http://code.google.com/p/html5shiv/

Page 41: Using HTML5 sensibly

Cue the purists of the web. “HTML should work without JavaScript!”

Page 43: Using HTML5 sensibly

Purist solution: add DIVs around the new elements.

.header,header,

.footer,footer,

.aside,aside,

.section,section{ display:block;}

Page 44: Using HTML5 sensibly

<!DOCTYPE html><html lang="en"> <head><meta charset="utf-8"> <title>HTML5, c'est moi, ou HTML...</title> <link rel="stylesheet" href="styles.css"> <script src="magic.js"></script> </head> <body> <div class="header"><header> <h1>Heading! Everybody duck!</h1> </header></div> <div class="section"><section> <p>I am content, hear me roar!</p> </section></div> <div class="footer"><footer> <p>By me</p> </footer></div></body></html>

Page 45: Using HTML5 sensibly

Bloody Internet Explorer! We always have to do things extra for it!

Page 46: Using HTML5 sensibly

All browsers fail in one way or another and need patches. Our job is to know them.

Luckily, there is help.

Page 47: Using HTML5 sensibly

http://www.modernizr.com/

Page 48: Using HTML5 sensibly

http://html5boilerplate.com/

Page 49: Using HTML5 sensibly

And as if by magic - the much shorter and pragmatic markup became more complex again.

Page 50: Using HTML5 sensibly
Page 51: Using HTML5 sensibly

<!doctype html> <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]--><!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]--><!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]--><!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]--><!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]--><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="shortcut icon" href="/favicon.ico"> <link rel="apple-touch-icon" href="/apple-touch-icon.png"> <link rel="stylesheet" href="css/style.css?v=2"> <script src="js/libs/modernizr-1.6.min.js"></script></head><body> <div id="container"> <header> </header> <div id="main"> </div> <footer> </footer> </div> <!-- end of #container --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"> </script> <script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.4.2.js"%3E%3C/script%3E'))</script> <!-- scripts concatenated and minified via ant build script--> <script src="js/plugins.js"></script> <script src="js/script.js"></script> <!-- end concatenated and minified scripts--> <!--[if lt IE 7 ]> <script src="js/libs/dd_belatedpng.js"></script> <script> DD_belatedPNG.fix('img, .png_bg'); </script> <![endif]--></body></html>

Page 52: Using HTML5 sensibly

<!doctype html> <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]--><!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]--><!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]--><!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]--><!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]--><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="shortcut icon" href="/favicon.ico"> <link rel="apple-touch-icon" href="/apple-touch-icon.png"> <link rel="stylesheet" href="css/style.css?v=2"> <script src="js/libs/modernizr-1.6.min.js"></script></head><body> <div id="container"> <header> </header> <div id="main"> </div> <footer> </footer> </div> <!-- end of #container --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"> </script>

<script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.4.2.js"%3E%3C/script%3E'))</script> <!-- scripts concatenated and minified via ant build script--> <script src="js/plugins.js"></script> <script src="js/script.js"></script> <!-- end concatenated and minified scripts--> <!--[if lt IE 7 ]> <script src="js/libs/dd_belatedpng.js"></script> <script> DD_belatedPNG.fix('img, .png_bg'); </script> <![endif]--></body></html>

Page 53: Using HTML5 sensibly

<!doctype html> <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]--><!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]--><!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]--><!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]--><!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]--><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="shortcut icon" href="/favicon.ico"> <link rel="apple-touch-icon" href="/apple-touch-icon.png"> <link rel="stylesheet" href="css/style.css?v=2"> <script src="js/libs/modernizr-1.6.min.js"></script></head><body> <div id="container"> <header> </header> <div id="main"> </div> <footer> </footer> </div> <!-- end of #container --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"> </script>

<script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.4.2.js"%3E%3C/script%3E'))</script> <!-- scripts concatenated and minified via ant build script--> <script src="js/plugins.js"></script> <script src="js/script.js"></script> <!-- end concatenated and minified scripts--> <!--[if lt IE 7 ]> <script src="js/libs/dd_belatedpng.js"></script> <script> DD_belatedPNG.fix('img, .png_bg'); </script> <![endif]--></body></html>

Page 54: Using HTML5 sensibly

One solution to use HTML5 APIs with legacy browsers is using polyfills.

Page 55: Using HTML5 sensibly

https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills

Page 56: Using HTML5 sensibly

?Should we shoe-horn new technology into legacy browsers?

Page 57: Using HTML5 sensibly

?Do patches add complexity as we need to test their performance?

Page 58: Using HTML5 sensibly

?How about moving IE<9 fixes to the server side? Padding with DIVs with classes and no JS for IE?

Page 59: Using HTML5 sensibly

Making video and audio simpler.

Page 60: Using HTML5 sensibly

Embedding audio and video is easy in HTML5<video src="interview.ogv" controls> <a href="interview.ogv">Download the video</a></video>

Page 61: Using HTML5 sensibly

To make all capable browsers play the video... <video controls> <source src="interview.mp4" type="video/mp4"> </source> <source src="interview.webm" type="video/webm"> </source> <source src="interview.ogv" type="video/ogg"> </source> <p>Download the <a href="interview.mp4">video in MP4 format</a>. </p></video>

Page 62: Using HTML5 sensibly

Where there is a need, there is an opportunity for a business.

Page 63: Using HTML5 sensibly
Page 64: Using HTML5 sensibly

However, there is a real problem for businesses.

Page 66: Using HTML5 sensibly

?Can we expect content creators to create video in many formats to support an open technology?

Page 67: Using HTML5 sensibly

?Can a service like vid.ly be trusted for content creation and storage?

Page 68: Using HTML5 sensibly

?Is HTML5 not applicable for premium content?

Page 69: Using HTML5 sensibly

It is time for all of us to take initiative and make this work.

Page 70: Using HTML5 sensibly

Question authority and call out wrong messaging.

Page 71: Using HTML5 sensibly

Bad use of technology doesn’t only break end user experiences - it breaks the web!http://gawker.com/#!5754678/what-should-our-new-national-anthem-be

Page 73: Using HTML5 sensibly

https://developer.mozilla.org/

Page 74: Using HTML5 sensibly

Thanks!

Chris Heilmann@codepo8http://icant.co.uk