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

Grundlagen moderner WebApps mit HTML5

Grundlagen moderner WebApps mit HTML5

Thorsten Rinne

September 26, 2012
Tweet

More Decks by Thorsten Rinne

Other Decks in Programming

Transcript

  1. Thorsten Rinne • 35 Jahre • Yatego GmbH, München –

    Senior Developer • Diplom-Informatiker (FH) • Twitter: @ThorstenRinne
  2. Sebastian Springer • 29 Jahre • Mayflower GmbH – Senior

    Developer / Team Lead • Diplom-Informatiker (FH) • Twitter: @basti_springer
  3. <video width="320" height="240" controls="controls"> <source src="movie.mp4" type="video/mp4" /> <source src="movie.ogg"

    type="video/ogg" /> Your browser does not support the video tag. :-( </video> <audio controls="controls"> <source src="sound.ogg" type="audio/ogg" /> <source src="sound.mp3" type="audio/mp3" /> Your browser does not support the audio tag. :-( </audio>
  4. „HTML5 is about moving from documents to applications and from

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

    var query = ‘SELECT * FROM users‘; db.query(query, function(err, results, fields) {...}; );
  8. Schnell installiert: Ubuntu (Linux) $ sudo apt-get install nodejs Homebrew

    (OS X) $ brew install node MacPorts (OS X) $ sudo port install nodejs ... und auch als Windows Installer! :-)
  9. 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‘);
  10. Bibliotheken als NPM • Socket.IO • Backbone.js • Underscore.js •

    express • Connect • MySQL, redis, CouchDB
  11. Tools auf node.js Basis • less • compass • uglifyjs

    • grunt.js Dazu aber später mehr!
  12. 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. }
  13. 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
  14. 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'); } main.js WebWorker
  15. <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
  16. 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); }); }
  17. 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
  18. 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>
  19. HTML 5 Microdata is machine- readable data in HTML. Recursion.

    :-) <div itemscope> <p> Mein Name ist <span itemprop="name">Thorsten</span>. </p> </div>
  20. 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
  21. 28 % 64 % 74 % 70 % 77 %

    87 % IE9 Mobile Safari Safari 6 Firefox 15 Opera 12 Chrome 22 html5test.com
  22. Was uns demnächst erwartet... • Internet Explorer 10 mit Windows

    8 (64% HTML5 Support) • viele neue Chrome- und Firefox-Versionen • Chrome auf Android im (Smart)-TV • Safari in Apple TV? • nach W3C – HTML 5.0 Recommendation Ende 2014 – HTML 5.1 Recommendation Ende 2016 – usw.
  23. Kontakt Sebastian Springer [email protected] Mayflower GmbH Mannhardtstr. 6 80538 München

    Deutschland @basti_springer https://github.com/sspringer82 Thorsten Rinne [email protected] Yatego GmbH Kobellstr. 15 80336 München Deutschland @ThorstenRinne https://github.com/thorsten