175
Thorsten Rinne / Sebastian Springer Webapplikationen reloaded mit node.js und HTML5 - Die Grundlagen

HTML5 und node.js Grundlagen

Embed Size (px)

Citation preview

Page 1: HTML5 und node.js Grundlagen

Thorsten Rinne / Sebastian Springer

Webapplikationen reloaded mit node.js und HTML5 - Die Grundlagen

Page 2: HTML5 und node.js Grundlagen

Thorsten Rinne

• 34 Jahre• Mayflower GmbH, München

– Senior Developer / Team Lead– Head of Open Source Labs

• Diplom-Informatiker (FH)• Twitter: @ThorstenRinne

Page 3: HTML5 und node.js Grundlagen

Sebastian Springer

• 29 Jahre• Mayflower GmbH

– Senior Developer / Team Lead• Diplom-Informatiker (FH)• Twitter: @basti_springer

Page 4: HTML5 und node.js Grundlagen

Wer seid ihr?

Page 5: HTML5 und node.js Grundlagen

Wir sprechen nicht über<video> und <audio>

Page 6: HTML5 und node.js Grundlagen

Und wir sprechen nicht über ...

Page 7: HTML5 und node.js Grundlagen

Flash ist tot.Spätestens in 5 Jahren.

(sagt sogar Adobe)

Page 8: HTML5 und node.js Grundlagen

Wer nutzt bereits...

Page 9: HTML5 und node.js Grundlagen

und wer bereits...

Page 10: HTML5 und node.js Grundlagen

HTML5 in einem Satz?

Page 11: HTML5 und node.js Grundlagen

„HTML5 is about moving from documents to applications and

from hacks to solutions.“

Chris Heilmann auf Twitter

Page 12: HTML5 und node.js Grundlagen

Was bedeutet HTML5 für Entwickler?

Page 13: HTML5 und node.js Grundlagen

HTML5 ~= HTML + CSS + JS

Page 14: HTML5 und node.js Grundlagen

1989HTML wird am CERN

entwickelt.

Page 15: HTML5 und node.js Grundlagen

1993Die IETF verlangt die erste Implementierung: Mosaic

Page 16: HTML5 und node.js Grundlagen

1996Tim Berners-Lee gründet das World

Wide Web Consortium (W3C)

Page 17: HTML5 und node.js Grundlagen

1996Browserkrieg:

Netscape vs. Microsoft

Page 18: HTML5 und node.js Grundlagen

- Der Browser ist kostenlos- Das Web ersetzt das OS- Java bringt Web Apps - 4 Versionen in 7 Jahren

- „kostenlos“ mit OS- 1995: 6 Entwickler- 1999: 1000 Entwickler- 6 Versionen in 6 Jahren

Netscape verlor den „Krieg“ ...

Page 19: HTML5 und node.js Grundlagen

The dark age of the Web...

Page 20: HTML5 und node.js Grundlagen

XHTML 2.0

Page 21: HTML5 und node.js Grundlagen

#sadpanda

Page 22: HTML5 und node.js Grundlagen

1999PHP 3.0 - MySQL 3.22

Apache 1.3

Page 23: HTML5 und node.js Grundlagen
Page 24: HTML5 und node.js Grundlagen

1999XMLHttpRequest Object

Page 25: HTML5 und node.js Grundlagen

Die Zeit verging ...

Page 26: HTML5 und node.js Grundlagen

seit Version 5.0 (1999)

seit Version 1.0 (2004)

seit Version 1.2 (2004)

seit Version 7.6 (2004)

Page 27: HTML5 und node.js Grundlagen

2005Ajax: A New Approach to Web

Applications

Blogposting von Jesse James Garret

Page 28: HTML5 und node.js Grundlagen
Page 29: HTML5 und node.js Grundlagen

Google Suggest

Google Mail

Google Maps

Page 30: HTML5 und node.js Grundlagen

2006Comet

Page 31: HTML5 und node.js Grundlagen
Page 32: HTML5 und node.js Grundlagen

Push Ajax

Push

Page 33: HTML5 und node.js Grundlagen

Was passiert hier?

Page 34: HTML5 und node.js Grundlagen

Contentvs.

Context

Page 35: HTML5 und node.js Grundlagen

Facebook ist eine Applikation!

Page 36: HTML5 und node.js Grundlagen

Pagevs.

Stream

Page 37: HTML5 und node.js Grundlagen

Twitter ist eine Applikation!

Page 38: HTML5 und node.js Grundlagen

Applikationen?

Page 39: HTML5 und node.js Grundlagen

Apps!

Page 40: HTML5 und node.js Grundlagen
Page 41: HTML5 und node.js Grundlagen
Page 42: HTML5 und node.js Grundlagen

online === offline

Page 43: HTML5 und node.js Grundlagen

Ist das das neue Web?

Page 44: HTML5 und node.js Grundlagen

Die Zukunft besteht aus Web Apps!

Page 45: HTML5 und node.js Grundlagen

Der mobile Browser ist (fast) identisch mit dem Desktop

Browser.

Page 46: HTML5 und node.js Grundlagen

Der Mobile Browser hat kurze Release-Zyklen. Der auf dem

Desktop inzwischen auch.

Page 47: HTML5 und node.js Grundlagen

Der Browser ist eine„cross platform

realtime runtime“.

Page 48: HTML5 und node.js Grundlagen

Was hat das nun mit HTML5 zu tun?

Page 49: HTML5 und node.js Grundlagen

Requests

Events

Page 50: HTML5 und node.js Grundlagen

2000: PHP chat style polling

Client Server

Page 51: HTML5 und node.js Grundlagen

Client Server

Hey, wazzup?

2000: PHP chat style polling

Page 52: HTML5 und node.js Grundlagen

Client Server

Um, nothing actually...Hey, wazzup?

2000: PHP chat style polling

Page 53: HTML5 und node.js Grundlagen

Client Server

Hey, wazzup?

1 sec

Um, nothing actually...

2000: PHP chat style polling

Page 54: HTML5 und node.js Grundlagen

Client Server

2000: PHP chat style polling

Page 55: HTML5 und node.js Grundlagen

Client Server

Hey, wazzup?

2000: PHP chat style polling

Page 56: HTML5 und node.js Grundlagen

Client Server

Hey, wazzup? Um, nothing actually...

2000: PHP chat style polling

Page 57: HTML5 und node.js Grundlagen

Client Server

Hey, wazzup? Um, nothing actually...

2000: PHP chat style polling

1 sec

Page 58: HTML5 und node.js Grundlagen

Client Server

2000: PHP chat style polling

Page 59: HTML5 und node.js Grundlagen

Client Server

Hey, wazzup?

2000: PHP chat style polling

Page 60: HTML5 und node.js Grundlagen

Client Server

Hey, wazzup? Um, nothing actually...

2000: PHP chat style polling

Page 61: HTML5 und node.js Grundlagen

Client Server

Hey, wazzup? Um, nothing actually...

2000: PHP chat style polling

1 sec

Page 62: HTML5 und node.js Grundlagen

Client Server

WTF???

2000: PHP chat style polling

Page 63: HTML5 und node.js Grundlagen

1 user = 1 req / secCPU #FAIL

Page 64: HTML5 und node.js Grundlagen

Client Server

2006: Comet style long poll

Page 65: HTML5 und node.js Grundlagen

Client Server

Hey, wazzup?

2006: Comet style long poll

Page 66: HTML5 und node.js Grundlagen

Client Server

Um, nothing actually...

1 sec

2006: Comet style long poll

Page 67: HTML5 und node.js Grundlagen

Client Server

Well ...

2006: Comet style long poll

1 sec

Page 68: HTML5 und node.js Grundlagen

Client Server

Wait ...

2006: Comet style long poll

1 sec

Page 69: HTML5 und node.js Grundlagen

Client Server

Uh, there is something!

2006: Comet style long poll

1 sec

Page 70: HTML5 und node.js Grundlagen

Client Server

No, nothing!

2006: Comet style long poll

1 sec

Page 71: HTML5 und node.js Grundlagen

Client Server

WTF???

2006: Comet style long poll

Page 72: HTML5 und node.js Grundlagen

1 user = 1 apache childMEMORY #FAIL

Page 73: HTML5 und node.js Grundlagen

Wir haben ein Problem

Page 74: HTML5 und node.js Grundlagen
Page 75: HTML5 und node.js Grundlagen

Wir brauchen Hilfe!

Page 76: HTML5 und node.js Grundlagen

MEMORY: WINCPU: 1/2 WIN

Page 77: HTML5 und node.js Grundlagen

Client

Client

Client

PHP Server

Page 78: HTML5 und node.js Grundlagen

Was ist node.js?

Page 79: HTML5 und node.js Grundlagen

Serverseitiges JS mit V8

Page 80: HTML5 und node.js Grundlagen

Eventgetriebene Architektur

Page 81: HTML5 und node.js Grundlagen

Asynchron

Page 83: HTML5 und node.js Grundlagen

Warum node.js?

Page 84: HTML5 und node.js Grundlagen

Es ist schnell.

Page 85: HTML5 und node.js Grundlagen

Nonblocking I/O durch Eventloop

Page 86: HTML5 und node.js Grundlagen

♥ Community Love ♥

Page 87: HTML5 und node.js Grundlagen

Schnelle, leichtgewichtige

Entwicklung

Page 88: HTML5 und node.js Grundlagen

Viele eingebaute Bibliotheken

EventsStreams

Debugger

URL

Query String

HTTP

OS

File System

Page 89: HTML5 und node.js Grundlagen
Page 90: HTML5 und node.js Grundlagen

Heile Welt?

Page 91: HTML5 und node.js Grundlagen

node.js hat auch seine

Schattenseiten.

Page 92: HTML5 und node.js Grundlagen

Single Process

Page 93: HTML5 und node.js Grundlagen

Statische Inhalte

Page 94: HTML5 und node.js Grundlagen

Sehr betriebssystemnah ...

Page 95: HTML5 und node.js Grundlagen

#sadpanda #nodejs

Page 96: HTML5 und node.js Grundlagen

node.js muss auch rechnen

Page 97: HTML5 und node.js Grundlagen

We ♥ node.js!

Page 98: HTML5 und node.js Grundlagen

Kenne die Schwächen deiner Infrastruktur!

Page 99: HTML5 und node.js Grundlagen

Modi

Page 100: HTML5 und node.js Grundlagen

Interaktiv

Page 101: HTML5 und node.js Grundlagen

Nicht interaktiv

$ node server.js

Page 102: HTML5 und node.js Grundlagen

Non-Blocking

Page 103: HTML5 und node.js Grundlagen

Non Blocking

sleep(10);echo ‘Hello, World‘;

vs.

setTimeout(console.log(‘Hello, World‘, 10000))

Page 104: HTML5 und node.js Grundlagen

$sql = ‘SELECT * FROM users‘;$result = $conn->query($sql);

vs.

var query = ‘SELECT * FROM users‘;db.query(query, function(err, results, fields) {...};);

Page 105: HTML5 und node.js Grundlagen

Webserver

Page 106: HTML5 und node.js Grundlagen

Webserver Codevar http = require(‘http‘);http.createServer( function(req, res) { res.writeHead( 200, {‘Content-Type‘: ‘text/plain‘} ); res.end(‘Hello, World‘); }).listen(1337, ‘127.0.0.1‘);

Page 107: HTML5 und node.js Grundlagen

Bibliotheken als NPM

• Socket.IO• Backbone.js• Underscore.js• express• Common.js• MySQL, redis, CouchDB

Page 108: HTML5 und node.js Grundlagen

Kleine Helfer für node.js

• Nodemon– https://github.com/remy/nodemon

• Forever– https://github.com/indexzero/forever

• Mehr?

Page 109: HTML5 und node.js Grundlagen

Und was ist mit dem Client?

Page 110: HTML5 und node.js Grundlagen

WebSockets if ("WebSocket" in window) { var ws = new WebSocket("ws://example.com/service"); ws.onopen = function() { // WebSocket is connected. // You can send data by send() method. ws.send("message to send");

// .... }; ws.onmessage = function (evt) { var received_msg = evt.data; }; ws.onclose = function() { // WebSocket is closed }; } else { // the browser doesn't support WebSockets. }

Page 111: HTML5 und node.js Grundlagen

GET /demo HTTP/1.1Upgrade: WebSocketConnection: UpgradeHost: example.comOrigin: http://example.comSec-WebSocket-Key1: 4 @1 46546xW%0l 1 5Sec-WebSocket-Key2: 12998 5 Y3 1 .P00 ^n:ds[4U

HTTP/1.1 101 WebSocket Protocol HandshakeUpgrade: WebSocketConnection: UpgradeSec-WebSocket-Origin: http://example.comSec-WebSocket-Location: ws://example.com/demoSec-WebSocket-Protocol: sample 8jKS'y:G*Co,Wxa-

Client

Server

Page 112: HTML5 und node.js Grundlagen
Page 113: HTML5 und node.js Grundlagen

Immer mehr Logik wandert in den Client. Weg vom Backend.

Page 114: HTML5 und node.js Grundlagen

var myWorker = new Worker('backgroundtask.js');

myWorker.onmessage = function(event) { alert(event.data); };

self.onmessage = function(event) { // Do some heavy work self.postMessage('Hello, Amsterdam'); }

backgroundtask.js

main.jsWebWorker

Page 115: HTML5 und node.js Grundlagen

Demo

Page 116: HTML5 und node.js Grundlagen
Page 117: HTML5 und node.js Grundlagen

MVC mit Backbone.js

Server (z.B. DB)

User

View

Model

Router

URLDOM

Read/Write

Page 118: HTML5 und node.js Grundlagen

<form> <input type="text" name="msg" value="My message" id="msg"> <input type="submit"> <h2>Ziel iFrame:</h2> <iframe id="iframe" src="postmessage.html"></iframe> </form> <script> var win = document.getElementById("iframe").contentWindow; addEvent(

document.getElementsByTagName('form')[0], 'submit', function (e) {

if (e.preventDefault) e.preventDefault(); win.postMessage(document.getElementById("msg").value, "http://www.phpconference.nl"); e.returnValue = false; return false; }); </script>

WebMessaging

Page 119: HTML5 und node.js Grundlagen

Geolocation if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( function(position) { var lat = position.coords.latitude; var lng = position.coords.longitude; var options = { position: new google.maps.LatLng(lat, lng) } var marker = new google.maps.Marker(options); marker.setMap(map); }); }

Page 120: HTML5 und node.js Grundlagen

Web Storage‣„kurzlebige“ Daten‣sessionStorage Object‣wird beim Schließen des Browsers gelöscht‣„langlebige“ Daten‣localStorage Objekt‣wird nicht beim Schließen des Browsers gelöscht‣produziert File I/O, läuft synchron

Safari/Chrome Firefox IE Opera

2 MB 5 MB ~ 200MB 5 MB 4 MB

Page 121: HTML5 und node.js Grundlagen

Web Storage <p>This page was requested <b> <script> if (!sessionStorage.pageCounter) { sessionStorage.setItem('pageCounter',0); } sessionStorage.setItem('pageCounter', parseInt(sessionStorage.pageCounter)+1); document.write(sessionStorage.pageCounter); </script> </b> times.</p> <p> <input value="sessionStorage leeren" type="button" onClick="sessionStorage.clear();location.reload(true);"> <input value="Seite laden" type="button" onClick="location.reload(true);"> </p>

Page 122: HTML5 und node.js Grundlagen

Demo

Page 123: HTML5 und node.js Grundlagen

HTML 5 Basics

Page 124: HTML5 und node.js Grundlagen

<!DOCTYPE html>

Page 125: HTML5 und node.js Grundlagen

Von HTML4 nach HTML5

KISSKeep it simple & stupid

Page 126: HTML5 und node.js Grundlagen

Redundante und kaputte Elementewerden entfernt.

Von HTML4 nach HTML5

Page 127: HTML5 und node.js Grundlagen

HTML5 verlangt explizit nach CSS.

Von HTML4 nach HTML5

Page 128: HTML5 und node.js Grundlagen

<meta http-equiv=“Content-Type“ content=“text/html;

charset=UTF-8“>

<meta charset=“UTF-8“>

Page 129: HTML5 und node.js Grundlagen

<a>ist flexibler

<a>, <area>erhalten ein media Attribut

Page 130: HTML5 und node.js Grundlagen

<a href=“http://m.twitter.com“ rel=“alternate“

media=“handheld“>Twitter Mobile</a>

Page 131: HTML5 und node.js Grundlagen

data Attribut

für eigene data-* Attribute

Page 132: HTML5 und node.js Grundlagen

Beispiel Facebook Like

<div class="fb-like" data-send="true" data-width="450" data-show-faces="true"></div>

Page 133: HTML5 und node.js Grundlagen

<section> Bereiche <address> und Überschriften

Page 134: HTML5 und node.js Grundlagen

<header><hgroup><nav>

<article><footer>

Page 135: HTML5 und node.js Grundlagen

<time><details><figure>

<figcaption><mark>

Page 136: HTML5 und node.js Grundlagen

<link rel="alternate" type="application/atom+xml" title="My Weblog feed" href="http://www.phpconference.de/feed/"> <link rel="search" type="application/opensearchdescription+xml" title="My Weblog search" href="http://www.phpconference.de/opensearch.xml"> <link rel="icon" href="/favicon.ico">

<link rel="pingback" href="http://www.phpconference.de/xmlrpc.php"> <link rel="prefetch" href="http://www.phpconference.de/main.php"> <link rel="archives" href="http://www.phpconference.de/archive/"> <link rel="external" href="http://www.php.net"> <link rel="license" href="http://www.gnu.org/licenses/gpl.html"> <link rel="nofollow" href="http://www.ruby-lang.org">

Page 137: HTML5 und node.js Grundlagen

<svg>Vektorgrafiken in XML

<canvas>Pixelgrafiken in JavaScript

Page 138: HTML5 und node.js Grundlagen

Demo

Page 139: HTML5 und node.js Grundlagen

HTML 5 Microdata is machine-readable data in HTML.

Recursion. :-)

<div itemscope> <p>

Mein Name ist <span itemprop="name">Thorsten</span>.</p>

</div>

Page 140: HTML5 und node.js Grundlagen

WebForms

Page 141: HTML5 und node.js Grundlagen

<input type="text" placeholder="Mayflower GmbH">

Page 142: HTML5 und node.js Grundlagen

<input type="text" maxlength="256" name="q" autofocus>

<input type="text" maxlength="256" name="q" required="required">

Page 143: HTML5 und node.js Grundlagen

<input type="tel" name="phonenumber">

<input type="url" name="url">

<input type="email" name="emailaddress">

Page 144: HTML5 und node.js Grundlagen

<input type="number" min="0" max="10" step="2" value="6" />

Page 145: HTML5 und node.js Grundlagen

<input type="range" min="0" max="10" step="2" value="6">

Page 146: HTML5 und node.js Grundlagen

<input type="text" x-webit-speech>

Page 147: HTML5 und node.js Grundlagen

<input type="date"> <input type="month"> <input type="week"> <input type="time"> <input type="datetime">

Page 148: HTML5 und node.js Grundlagen

<input type="color">

Page 149: HTML5 und node.js Grundlagen

Demo

Page 150: HTML5 und node.js Grundlagen

CSS3

Page 151: HTML5 und node.js Grundlagen

.row:nth-child(even) { background: #cccccc; } .row:nth-child(odd) { background: #ffffff; }

row 1

row 2

row 3

row 4

Page 152: HTML5 und node.js Grundlagen

@font-face { font-family: 'Papyrus'; src: url(Papyrus.otf); } header { font-family: 'Papyrus'; }

Hallo, Welt!

Page 153: HTML5 und node.js Grundlagen

Mehr CSS3 Features...

Page 154: HTML5 und node.js Grundlagen

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit

Multi-column layouts

Page 155: HTML5 und node.js Grundlagen

OpacityOpacityOpacityOpacityOpacity

Page 156: HTML5 und node.js Grundlagen

HSL / HSLA Farben

Page 157: HTML5 und node.js Grundlagen

Endlich runde Ecken! :-)

Page 158: HTML5 und node.js Grundlagen

Gradienten

Page 159: HTML5 und node.js Grundlagen

Shadows

Page 160: HTML5 und node.js Grundlagen

Shadows

Page 161: HTML5 und node.js Grundlagen

Transitions und Animations

Page 162: HTML5 und node.js Grundlagen

BrowserSupport :-)

Page 163: HTML5 und node.js Grundlagen

30 %

64 % 64 %69 % 69 %

79 %

IE9 Mobile Safari Safari 5.1 Firefox 10 Opera 11.6Chrome 17

Page 164: HTML5 und node.js Grundlagen

Was uns 2012 noch erwartet...

• Internet Explorer 10 mit Windows 8 (64% HTML5 Support)

• Safari 5.2 (74% HTML5 Support)

• Opera 12(72% HTML5 Support)

• viele neue Chrome- und Firefox-Versionen• Chrome on Android im TV• evtl. Mobile Safari im TV

Page 165: HTML5 und node.js Grundlagen

Kleine Helferfür HTML5

Page 166: HTML5 und node.js Grundlagen
Page 167: HTML5 und node.js Grundlagen
Page 168: HTML5 und node.js Grundlagen
Page 169: HTML5 und node.js Grundlagen

caniuse.com

Page 170: HTML5 und node.js Grundlagen

html5test.com

Page 171: HTML5 und node.js Grundlagen

Kleine Helferfür CSS

Page 172: HTML5 und node.js Grundlagen
Page 173: HTML5 und node.js Grundlagen

Fragen?

Page 174: HTML5 und node.js Grundlagen

Danke!

http://joind.in/4692

Page 175: HTML5 und node.js Grundlagen

Kontakt

Sebastian [email protected]+49 89 242054-1120

Mayflower GmbHMannhardtstr. 680538 MünchenDeutschland

@basti_springer

Thorsten [email protected]+49 89 242054-1131

Mayflower GmbHMannhardtstr. 680538 MünchenDeutschland

@ThorstenRinne