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

HTML5 vs App Nativo

HTML5 vs App Nativo

HTML5 é capaz de aguentar o tranco?

Avatar for mauriliohrc

mauriliohrc

February 22, 2013
Tweet

More Decks by mauriliohrc

Other Decks in Programming

Transcript

  1. HTML5 vs NATIVO @ m a u r i l

    i o h r c Friday, February 22, 13
  2. Quem é esse cara estranho aqui na frente? Twitter: mauriliohrc

    Github: mauriliohrc Youtube: KiwiOfficeHour Friday, February 22, 13
  3. Recursos Internet Armazenamento Conectividade Sensores Notificações Animações Cache <!DOCTYPE HTML>

    <html manifest="cache.manifest"> <body> … </body> </html> Friday, February 22, 13
  4. Recursos Internet Armazenamento Conectividade Sensores Notificações Animações Cache CACHE MANIFEST

    NETWORK: /checking.cgi FALLBACK: /css/theme.css CACHE: /js/main.js /css/index.css http://files/images/scene.jpg http://files/images/world.jpg Friday, February 22, 13
  5. Recursos Internet Armazenamento Conectividade Sensores Notificações Animações Storage if  (typeof(Storage)!==”undefined”)

     {    //  Disponível }  else  {    //  Não  disponível } localStorage.getItem("bar"); localStorage[“bar”] localStorage.setItem("bar",  obj); localStorage[“bar”]  =  obj Friday, February 22, 13
  6. Recursos Internet Armazenamento Conectividade Sensores Notificações Animações Storage var  testObject

     =  {  'one':  1,  'two':  2,  'three':  3  }; //  Put  the  object  into  storage localStorage.setItem('testObject',   JSON.stringify(testObject)); //  Retrieve  the  object  from  storage var  retrievedObject  =   localStorage.getItem('testObject'); console.log('retrievedObject:  ',   JSON.parse(retrievedObject)); Friday, February 22, 13
  7. Recursos Internet Armazenamento Conectividade Sensores Notificações Animações Network <script type="text/javascript"

    src="http://local/user? id=1234&jsonp=parseResponse"> </script> parseResponse({"Name": "Foo", "Id" : 1234, "Rank": 7}); Friday, February 22, 13
  8. Recursos Internet Armazenamento Conectividade Sensores Notificações Animações Network var connection

    = new WebSocket('ws:// html5rocks.websocket.org/echo', ['soap', 'xmpp']); // Sending String connection.send('your message'); // Sending canvas ImageData as ArrayBuffer var img = canvas_context.getImageData(0, 0, 400, 320); var binary = new Uint8Array(img.data.length); for (var i = 0; i < img.data.length; i++) { binary[i] = img.data[i]; } connection.send(binary.buffer); // Sending file as Blob var file = document.querySelector('input[type="file"]').files[0]; connection.send(file); Friday, February 22, 13
  9. Recursos Internet Armazenamento Conectividade Sensores Notificações Animações Sensores GeoLocation <script>

    function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { // não suportado (IE < 9) } function showPosition(position) { var latitude = position.coords.latitude; var longitude = position.coords.longitude; } </script> Friday, February 22, 13
  10. Recursos Internet Armazenamento Conectividade Sensores Notificações Animações Notificações if (!!window.EventSource)

    { var source = new EventSource('stream.php'); } else { // Result to xhr polling :( } source.addEventListener('message', function(e) { console.log(e.data); }, false); source.addEventListener('open', function(e) { // Connection was opened. }, false); source.addEventListener('error', function(e) { if (e.readyState == EventSource.CLOSED) { // Connection was closed. } }, false); Friday, February 22, 13
  11. Recursos Internet Armazenamento Conectividade Sensores Notificações Animações Notificações <?php header('Content-Type:

    text/event-stream'); header('Cache-Control: no-cache'); function sendMsg($id, $msg) { echo "id: $id" . PHP_EOL; echo "data: $msg" . PHP_EOL; echo PHP_EOL; ob_flush(); flush(); } $serverTime = time(); sendMsg($serverTime, 'server time: ' . date("h:i:s", time())); Friday, February 22, 13