Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Webapplikationen reloaded mit HTML5 und node.js

Webapplikationen reloaded mit HTML5 und node.js

Thorsten Rinne

April 11, 2012
Tweet

More Decks by Thorsten Rinne

Other Decks in Technology

Transcript

  1. Thorsten Rinne • 34 Jahre • Mayflower GmbH, München –

    Senior Developer / Team Lead – Head of Open Source Labs • Diplom-Informatiker (FH) • Twitter: @ThorstenRinne
  2. Sebastian Springer • 29 Jahre • Mayflower GmbH – Senior

    Developer / Team Lead • Diplom-Informatiker (FH) • Twitter: @basti_springer
  3. „HTML5 is about moving from documents to applications and from

    hacks to solutions.“ Chris Heilmann auf Twitter
  4. - 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“ ...
  5. $sql = ‘SELECT * FROM users‘; $result = $conn->query($sql); vs.

    var query = ‘SELECT * FROM users‘; db.query(query, function(err, results, fields) {...}; );
  6. Webserver Code var 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‘);
  7. Bibliotheken als NPM • Socket.IO • Backbone.js • Underscore.js •

    express • Common.js • MySQL, redis, CouchDB
  8. 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. }
  9. GET /demo HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: example.com Origin:

    http://example.com Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5 Sec-WebSocket-Key2: 12998 5 Y3 1 .P00 ^n:ds[4U HTTP/1.1 101 WebSocket Protocol Handshake Upgrade: WebSocket Connection: Upgrade Sec-WebSocket-Origin: http://example.com Sec-WebSocket-Location: ws://example.com/demo Sec-WebSocket-Protocol: sample 8jKS'y:G*Co,Wxa- Client Server
  10. 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.js WebWorker
  11. <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
  12. 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); }); }
  13. 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
  14. 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>
  15. <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">
  16. HTML 5 Microdata is machine- readable data in HTML. Recursion.

    :-) <div itemscope> <p> Mein Name ist <span itemprop="name">Thorsten</span>. </p> </div>
  17. 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 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 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 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 Multi-column layouts
  18. 30 % 64 % 64 % 69 % 69 %

    79 % IE9 Mobile Safari Safari 5.1 Firefox 10 Opera 11.6 Chrome 17
  19. 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
  20. Kontakt Sebastian Springer [email protected] +49 89 242054-1120 Mayflower GmbH Mannhardtstr.

    6 80538 München Deutschland @basti_springer Thorsten Rinne [email protected] +49 89 242054-1131 Mayflower GmbH Mannhardtstr. 6 80538 München Deutschland @ThorstenRinne