SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
Offline Strategien für
HTML5 (Web) Applikationen
  Stephan Hochdörfer, bitExpert AG
Offline Strategien für HTML5 (Web) Applikationen

 Über mich

  Stephan Hochdörfer, bitExpert AG

  Head of IT

  PHP Entwickler seit 1999

  S.Hochdoerfer@bitExpert.de

  @shochdoerfer
Offline Strategien für HTML5 (Web) Applikationen

 Was heißt „offline“?
Offline Strategien für HTML5 (Web) Applikationen

 Was heißt „offline“?

                      Applikation

                            vs.

            User-Generated Content
Offline Strategien für HTML5 (Web) Applikationen

 Application Cache für statische Ressourcen
 <!­­ clock.html ­­>
 <!DOCTYPE HTML>
 <html>
  <head>
   <title>Clock</title>
   <script src="clock.js"></script>
   <link rel="stylesheet" href="clock.css">
  </head>
  <body>
   <p>The time is: <output id="clock"></output></p>
  </body>
 </html>

 /* clock.css */
 output { font: 2em sans­serif; }

 /* clock.js */
 setTimeout(function () {
     document.getElementById('clock').value = new Date();
 }, 1000);
Offline Strategien für HTML5 (Web) Applikationen

 Application Cache für statische Ressourcen
 CACHE MANIFEST
 # 2012­09­16
 clock.html
 clock.css
 clock.js
Offline Strategien für HTML5 (Web) Applikationen

 Application Cache für statische Ressourcen
 <!­­ clock.html ­­>
 <!DOCTYPE HTML>
 <html manifest="cache.manifest">
  <head>
   <title>Clock</title>
   <script src="clock.js"></script>
   <link rel="stylesheet" href="clock.css">
  </head>
  <body>
   <p>The time is: <output id="clock"></output></p>
  </body>
 </html>
Offline Strategien für HTML5 (Web) Applikationen

 Application Cache Scripting...
 // events fired by window.applicationCache
 window.applicationCache.onchecking = function(e) 
 {log("Checking for updates");}
 window.applicationCache.onnoupdate = function(e) 
 {log("No updates");}
 window.applicationCache.onupdateready = function(e) 
 {log("Update ready");}
 window.applicationCache.onobsolete = function(e) 
 {log("Obsolete");}
 window.applicationCache.ondownloading = function(e) 
 {log("Downloading");}
 window.applicationCache.oncached = function(e) 
 {log("Cached");}
 window.applicationCache.onerror = function(e) 
 {log("Error");}

 // Log each file
 window.applicationCache.onprogress = function(e) {
   log("Progress: downloaded file " + counter);
   counter++;
 };
Offline Strategien für HTML5 (Web) Applikationen

 Offline Storage: User-Generated content...
Offline Strategien für HTML5 (Web) Applikationen

 Offline Storage: User-Generated content...




     Web Storage, Web SQL Database,
           IndexedDB, File API
Offline Strategien für HTML5 (Web) Applikationen

 Web Storage
Offline Strategien für HTML5 (Web) Applikationen

 Web Storage: 2 Möglichkeiten




       localStorage vs. sessionStorage
Offline Strategien für HTML5 (Web) Applikationen

 Web Storage: localStorage
 var myVar = 123;
 var myObj = {name: "Stephan"};

 // write scalar value to localStorage
 localStorage.setItem('myVar', myVar);

 // read scalar value from localStorage
 myVar = localStorage.getItem('myVar');

 // write object to localStorage
 localStorage.setItem('myObj', JSON.stringify(myObj));

 // read object from localStorage
 myObj = JSON.parse(localStorage.getItem('myObj'));
Offline Strategien für HTML5 (Web) Applikationen

 Web Storage: localStorage
 var myVar = 123;
 var myObj = {name: "Stephan"};

 // write scalar value to localStorage
 localStorage['myVar'] = myVar;

 // read scalar value from localStorage
 myVar = localStorage['myVar'];

 // write object to localStorage
 localStorage['myObj'] = JSON.stringify(myObj);

 // read object from localStorage
 myObj = JSON.parse(localStorage['myObj']);
Offline Strategien für HTML5 (Web) Applikationen

 Web Storage: sessionStorage
 var myVar = 123;
 var myObj = {name: "Stephan"};

 // write scalar value to sessionStorage
 sessionStorage['myVar'] = myVar;

 // read scalar value from sessionStorage
 myVar = sessionStorage['myVar'];

 // write object to sessionStorage
 sessionStorage['myObj'] = JSON.stringify(myObj);

 // read object from sessionStorage
 myObj = JSON.parse(sessionStorage['myObj']);
Offline Strategien für HTML5 (Web) Applikationen

 Web SQL Database
Offline Strategien für HTML5 (Web) Applikationen

 Web SQL Database
 function prepareDatabase(ready, error) {
   return openDatabase('documents', '1.0', 
     'Offline document storage', 5*1024*1024, function 
 (db) {
     db.changeVersion('', '1.0', function (t) {
       t.executeSql('CREATE TABLE docids (id, name)');
     }, error);
   });
 }

 function showDocCount(db, span) {
   db.readTransaction(function (t) {
     t.executeSql('SELECT COUNT(*) AS c FROM docids', [], 
       function (t, r) {
          span.textContent = r.rows[0].c;
       }, function (t, e) {
          // couldn't read database
          span.textContent = '(unknown: ' + e.message + 
 ')';
     });
   });
 }
Offline Strategien für HTML5 (Web) Applikationen

 IndexedDB
Offline Strategien für HTML5 (Web) Applikationen

 IndexedDB – Daten hinzufügen
 indexedDB.addTodo = function() {
   var db = todoDB.indexedDB.db;
   var trans = db.transaction(['todo'], 
 IDBTransaction.READ_WRITE);
   var store = trans.objectStore('todo');

   var data = {
     "text": todoText,
     "timeStamp": new Date().getTime()
   };

   var request = store.put(data);
   request.onsuccess = function(e) {
     todoDB.indexedDB.getAllTodoItems();
   };
   request.onerror = function(e) {
     console.log("Failed adding items due to: ", e);
   };
 };
Offline Strategien für HTML5 (Web) Applikationen

 IndexedDB – Daten auslesen
 function show() {
   var request = window.indexedDB.open("todos");
   request.onsuccess = function(event) {
     var db = todoDB.indexedDB.db;
     var trans = db.transaction(["todo"], 
         IDBTransaction.READ_ONLY);
     var request = trans.objectStore("todo").openCursor();
     var ul = document.createElement("ul");

     request.onsuccess = function(event) {
       var cursor = request.result || event.result;
       // If cursor is null, enumeration completed
       if(!cursor) {
         document.getElementById("todos").appendChild(ul);
         return;
       }

       var li = document.createElement("li");
       li.textContent = cursor.value.text;
       ul.appendChild(li);
       cursor.continue();
     }}}
Offline Strategien für HTML5 (Web) Applikationen

 File API
Offline Strategien für HTML5 (Web) Applikationen

 File API – Zugriff erfragen
 function onInitFs(fs) {
   console.log('Opened file system: ' + fs.name);
 }

 function errorHandler(e) {
   console.log('Error: ' + e.code);
 }

 window.requestFileSystem(window.TEMPORARY, 5*1024*1024 
 /*5MB*/, onInitFs, errorHandler);
Offline Strategien für HTML5 (Web) Applikationen
Offline Strategien für HTML5 (Web) Applikationen

 File API – Datei erzeugen
 function onInitFs(fs) {
   fs.root.getFile('log.txt', 
   {create: true, exclusive: true}, 
   function(fileEntry) {
     // fileEntry.name == 'log.txt'
     // fileEntry.fullPath == '/log.txt'
   }, errorHandler);
 }

 window.requestFileSystem(window.TEMPORARY, 5*1024*1024 
 /*5MB*/, onInitFs, errorHandler);
Offline Strategien für HTML5 (Web) Applikationen

 File API – Datei auslesen
 function onInitFs(fs) {
   fs.root.getFile('log.txt', {}, 
   function(fileEntry) {
     fileEntry.file(function(file) {
        var reader = new FileReader();

        reader.onloadend = function(e) {
          var txtArea   = 
               document.createElement('textarea');
          txtArea.value = this.result;
          document.body.appendChild(txtArea);
        };
        reader.readAsText(file);
     }, errorHandler);
   }, errorHandler);
 }

 window.requestFileSystem(window.TEMPORARY, 5*1024*1024 
 /*5MB*/, onInitFs, errorHandler);
Offline Strategien für HTML5 (Web) Applikationen

 File API – Verzeichnis anlegen
 function onInitFs(fs) {
    fs.root.getDirectory('MyFolder', {create: true}, 
    function(dirEntry) {
     // do stuff...
     }, errorHandler);
 }

 window.requestFileSystem(window.TEMPORARY, 5*1024*1024 
 /*5MB*/, onInitFs, errorHandler);
Vielen Dank!

Weitere ähnliche Inhalte

Mehr von Stephan Hochdörfer

Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...Stephan Hochdörfer
 
Phing for power users - frOSCon8
Phing for power users - frOSCon8Phing for power users - frOSCon8
Phing for power users - frOSCon8Stephan Hochdörfer
 
Offline strategies for HTML5 web applications - frOSCon8
Offline strategies for HTML5 web applications - frOSCon8Offline strategies for HTML5 web applications - frOSCon8
Offline strategies for HTML5 web applications - frOSCon8Stephan Hochdörfer
 
Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13Stephan Hochdörfer
 
Real World Dependency Injection - oscon13
Real World Dependency Injection - oscon13Real World Dependency Injection - oscon13
Real World Dependency Injection - oscon13Stephan Hochdörfer
 
Dependency Injection in PHP - dwx13
Dependency Injection in PHP - dwx13Dependency Injection in PHP - dwx13
Dependency Injection in PHP - dwx13Stephan Hochdörfer
 
Offline Strategien für HTML5 Web Applikationen - dwx13
Offline Strategien für HTML5 Web Applikationen - dwx13 Offline Strategien für HTML5 Web Applikationen - dwx13
Offline Strategien für HTML5 Web Applikationen - dwx13 Stephan Hochdörfer
 
Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Stephan Hochdörfer
 
Offline Strategies for HTML5 Web Applications - ipc13
Offline Strategies for HTML5 Web Applications - ipc13Offline Strategies for HTML5 Web Applications - ipc13
Offline Strategies for HTML5 Web Applications - ipc13Stephan Hochdörfer
 
Offline-Strategien für HTML5 Web Applikationen - wmka
Offline-Strategien für HTML5 Web Applikationen - wmkaOffline-Strategien für HTML5 Web Applikationen - wmka
Offline-Strategien für HTML5 Web Applikationen - wmkaStephan Hochdörfer
 
Offline-Strategien für HTML5 Web Applikationen - bedcon13
Offline-Strategien für HTML5 Web Applikationen - bedcon13Offline-Strategien für HTML5 Web Applikationen - bedcon13
Offline-Strategien für HTML5 Web Applikationen - bedcon13Stephan Hochdörfer
 
Real World Dependency Injection - phpugffm13
Real World Dependency Injection - phpugffm13Real World Dependency Injection - phpugffm13
Real World Dependency Injection - phpugffm13Stephan Hochdörfer
 
Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Stephan Hochdörfer
 
Offline strategies for HTML5 web applications - ConFoo13
Offline strategies for HTML5 web applications - ConFoo13Offline strategies for HTML5 web applications - ConFoo13
Offline strategies for HTML5 web applications - ConFoo13Stephan Hochdörfer
 
Offline strategies for HTML5 web applications - IPC12
Offline strategies for HTML5 web applications - IPC12Offline strategies for HTML5 web applications - IPC12
Offline strategies for HTML5 web applications - IPC12Stephan Hochdörfer
 
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12Stephan Hochdörfer
 
Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012Stephan Hochdörfer
 
Wie Software-Generatoren die Welt verändern können - Herbstcampus12
Wie Software-Generatoren die Welt verändern können - Herbstcampus12Wie Software-Generatoren die Welt verändern können - Herbstcampus12
Wie Software-Generatoren die Welt verändern können - Herbstcampus12Stephan Hochdörfer
 

Mehr von Stephan Hochdörfer (20)

Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
 
Phing for power users - frOSCon8
Phing for power users - frOSCon8Phing for power users - frOSCon8
Phing for power users - frOSCon8
 
Offline strategies for HTML5 web applications - frOSCon8
Offline strategies for HTML5 web applications - frOSCon8Offline strategies for HTML5 web applications - frOSCon8
Offline strategies for HTML5 web applications - frOSCon8
 
Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13
 
Real World Dependency Injection - oscon13
Real World Dependency Injection - oscon13Real World Dependency Injection - oscon13
Real World Dependency Injection - oscon13
 
Dependency Injection in PHP - dwx13
Dependency Injection in PHP - dwx13Dependency Injection in PHP - dwx13
Dependency Injection in PHP - dwx13
 
Offline Strategien für HTML5 Web Applikationen - dwx13
Offline Strategien für HTML5 Web Applikationen - dwx13 Offline Strategien für HTML5 Web Applikationen - dwx13
Offline Strategien für HTML5 Web Applikationen - dwx13
 
Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13
 
Offline Strategies for HTML5 Web Applications - ipc13
Offline Strategies for HTML5 Web Applications - ipc13Offline Strategies for HTML5 Web Applications - ipc13
Offline Strategies for HTML5 Web Applications - ipc13
 
Offline-Strategien für HTML5 Web Applikationen - wmka
Offline-Strategien für HTML5 Web Applikationen - wmkaOffline-Strategien für HTML5 Web Applikationen - wmka
Offline-Strategien für HTML5 Web Applikationen - wmka
 
Offline-Strategien für HTML5 Web Applikationen - bedcon13
Offline-Strategien für HTML5 Web Applikationen - bedcon13Offline-Strategien für HTML5 Web Applikationen - bedcon13
Offline-Strategien für HTML5 Web Applikationen - bedcon13
 
Real World Dependency Injection - phpugffm13
Real World Dependency Injection - phpugffm13Real World Dependency Injection - phpugffm13
Real World Dependency Injection - phpugffm13
 
Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Testing untestable code - ConFoo13
Testing untestable code - ConFoo13
 
A Phing fairy tale - ConFoo13
A Phing fairy tale - ConFoo13A Phing fairy tale - ConFoo13
A Phing fairy tale - ConFoo13
 
Offline strategies for HTML5 web applications - ConFoo13
Offline strategies for HTML5 web applications - ConFoo13Offline strategies for HTML5 web applications - ConFoo13
Offline strategies for HTML5 web applications - ConFoo13
 
Testing untestable code - IPC12
Testing untestable code - IPC12Testing untestable code - IPC12
Testing untestable code - IPC12
 
Offline strategies for HTML5 web applications - IPC12
Offline strategies for HTML5 web applications - IPC12Offline strategies for HTML5 web applications - IPC12
Offline strategies for HTML5 web applications - IPC12
 
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12
Große Systeme, lose Kopplung, Spaß bei der Arbeit! - WDC12
 
Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012
 
Wie Software-Generatoren die Welt verändern können - Herbstcampus12
Wie Software-Generatoren die Welt verändern können - Herbstcampus12Wie Software-Generatoren die Welt verändern können - Herbstcampus12
Wie Software-Generatoren die Welt verändern können - Herbstcampus12
 

Offline-Strategien für HTML5Web Applikationen - WMMRN12

  • 1. Offline Strategien für HTML5 (Web) Applikationen Stephan Hochdörfer, bitExpert AG
  • 2. Offline Strategien für HTML5 (Web) Applikationen Über mich  Stephan Hochdörfer, bitExpert AG  Head of IT  PHP Entwickler seit 1999  S.Hochdoerfer@bitExpert.de  @shochdoerfer
  • 3.
  • 4.
  • 5.
  • 6. Offline Strategien für HTML5 (Web) Applikationen Was heißt „offline“?
  • 7. Offline Strategien für HTML5 (Web) Applikationen Was heißt „offline“? Applikation vs. User-Generated Content
  • 8. Offline Strategien für HTML5 (Web) Applikationen Application Cache für statische Ressourcen <!­­ clock.html ­­> <!DOCTYPE HTML> <html>  <head>   <title>Clock</title>   <script src="clock.js"></script>   <link rel="stylesheet" href="clock.css">  </head>  <body>   <p>The time is: <output id="clock"></output></p>  </body> </html> /* clock.css */ output { font: 2em sans­serif; } /* clock.js */ setTimeout(function () {     document.getElementById('clock').value = new Date(); }, 1000);
  • 9. Offline Strategien für HTML5 (Web) Applikationen Application Cache für statische Ressourcen CACHE MANIFEST # 2012­09­16 clock.html clock.css clock.js
  • 10. Offline Strategien für HTML5 (Web) Applikationen Application Cache für statische Ressourcen <!­­ clock.html ­­> <!DOCTYPE HTML> <html manifest="cache.manifest">  <head>   <title>Clock</title>   <script src="clock.js"></script>   <link rel="stylesheet" href="clock.css">  </head>  <body>   <p>The time is: <output id="clock"></output></p>  </body> </html>
  • 11. Offline Strategien für HTML5 (Web) Applikationen Application Cache Scripting... // events fired by window.applicationCache window.applicationCache.onchecking = function(e)  {log("Checking for updates");} window.applicationCache.onnoupdate = function(e)  {log("No updates");} window.applicationCache.onupdateready = function(e)  {log("Update ready");} window.applicationCache.onobsolete = function(e)  {log("Obsolete");} window.applicationCache.ondownloading = function(e)  {log("Downloading");} window.applicationCache.oncached = function(e)  {log("Cached");} window.applicationCache.onerror = function(e)  {log("Error");} // Log each file window.applicationCache.onprogress = function(e) {   log("Progress: downloaded file " + counter);   counter++; };
  • 12. Offline Strategien für HTML5 (Web) Applikationen Offline Storage: User-Generated content...
  • 13. Offline Strategien für HTML5 (Web) Applikationen Offline Storage: User-Generated content... Web Storage, Web SQL Database, IndexedDB, File API
  • 14. Offline Strategien für HTML5 (Web) Applikationen Web Storage
  • 15. Offline Strategien für HTML5 (Web) Applikationen Web Storage: 2 Möglichkeiten localStorage vs. sessionStorage
  • 16. Offline Strategien für HTML5 (Web) Applikationen Web Storage: localStorage var myVar = 123; var myObj = {name: "Stephan"}; // write scalar value to localStorage localStorage.setItem('myVar', myVar); // read scalar value from localStorage myVar = localStorage.getItem('myVar'); // write object to localStorage localStorage.setItem('myObj', JSON.stringify(myObj)); // read object from localStorage myObj = JSON.parse(localStorage.getItem('myObj'));
  • 17. Offline Strategien für HTML5 (Web) Applikationen Web Storage: localStorage var myVar = 123; var myObj = {name: "Stephan"}; // write scalar value to localStorage localStorage['myVar'] = myVar; // read scalar value from localStorage myVar = localStorage['myVar']; // write object to localStorage localStorage['myObj'] = JSON.stringify(myObj); // read object from localStorage myObj = JSON.parse(localStorage['myObj']);
  • 18. Offline Strategien für HTML5 (Web) Applikationen Web Storage: sessionStorage var myVar = 123; var myObj = {name: "Stephan"}; // write scalar value to sessionStorage sessionStorage['myVar'] = myVar; // read scalar value from sessionStorage myVar = sessionStorage['myVar']; // write object to sessionStorage sessionStorage['myObj'] = JSON.stringify(myObj); // read object from sessionStorage myObj = JSON.parse(sessionStorage['myObj']);
  • 19. Offline Strategien für HTML5 (Web) Applikationen Web SQL Database
  • 20. Offline Strategien für HTML5 (Web) Applikationen Web SQL Database function prepareDatabase(ready, error) {   return openDatabase('documents', '1.0',      'Offline document storage', 5*1024*1024, function  (db) {     db.changeVersion('', '1.0', function (t) {       t.executeSql('CREATE TABLE docids (id, name)');     }, error);   }); } function showDocCount(db, span) {   db.readTransaction(function (t) {     t.executeSql('SELECT COUNT(*) AS c FROM docids', [],        function (t, r) {          span.textContent = r.rows[0].c;       }, function (t, e) {          // couldn't read database          span.textContent = '(unknown: ' + e.message +  ')';     });   }); }
  • 21. Offline Strategien für HTML5 (Web) Applikationen IndexedDB
  • 22. Offline Strategien für HTML5 (Web) Applikationen IndexedDB – Daten hinzufügen indexedDB.addTodo = function() {   var db = todoDB.indexedDB.db;   var trans = db.transaction(['todo'],  IDBTransaction.READ_WRITE);   var store = trans.objectStore('todo');   var data = {     "text": todoText,     "timeStamp": new Date().getTime()   };   var request = store.put(data);   request.onsuccess = function(e) {     todoDB.indexedDB.getAllTodoItems();   };   request.onerror = function(e) {     console.log("Failed adding items due to: ", e);   }; };
  • 23. Offline Strategien für HTML5 (Web) Applikationen IndexedDB – Daten auslesen function show() {   var request = window.indexedDB.open("todos");   request.onsuccess = function(event) {     var db = todoDB.indexedDB.db;     var trans = db.transaction(["todo"],          IDBTransaction.READ_ONLY);     var request = trans.objectStore("todo").openCursor();     var ul = document.createElement("ul");     request.onsuccess = function(event) {       var cursor = request.result || event.result;       // If cursor is null, enumeration completed       if(!cursor) {         document.getElementById("todos").appendChild(ul);         return;       }       var li = document.createElement("li");       li.textContent = cursor.value.text;       ul.appendChild(li);       cursor.continue();     }}}
  • 24. Offline Strategien für HTML5 (Web) Applikationen File API
  • 25. Offline Strategien für HTML5 (Web) Applikationen File API – Zugriff erfragen function onInitFs(fs) {   console.log('Opened file system: ' + fs.name); } function errorHandler(e) {   console.log('Error: ' + e.code); } window.requestFileSystem(window.TEMPORARY, 5*1024*1024  /*5MB*/, onInitFs, errorHandler);
  • 26. Offline Strategien für HTML5 (Web) Applikationen
  • 27. Offline Strategien für HTML5 (Web) Applikationen File API – Datei erzeugen function onInitFs(fs) {   fs.root.getFile('log.txt',    {create: true, exclusive: true},    function(fileEntry) {     // fileEntry.name == 'log.txt'     // fileEntry.fullPath == '/log.txt'   }, errorHandler); } window.requestFileSystem(window.TEMPORARY, 5*1024*1024  /*5MB*/, onInitFs, errorHandler);
  • 28. Offline Strategien für HTML5 (Web) Applikationen File API – Datei auslesen function onInitFs(fs) {   fs.root.getFile('log.txt', {},    function(fileEntry) {     fileEntry.file(function(file) {        var reader = new FileReader();        reader.onloadend = function(e) {          var txtArea   =                document.createElement('textarea');          txtArea.value = this.result;          document.body.appendChild(txtArea);        };        reader.readAsText(file);     }, errorHandler);   }, errorHandler); } window.requestFileSystem(window.TEMPORARY, 5*1024*1024  /*5MB*/, onInitFs, errorHandler);
  • 29. Offline Strategien für HTML5 (Web) Applikationen File API – Verzeichnis anlegen function onInitFs(fs) {    fs.root.getDirectory('MyFolder', {create: true},     function(dirEntry) {     // do stuff...     }, errorHandler); } window.requestFileSystem(window.TEMPORARY, 5*1024*1024  /*5MB*/, onInitFs, errorHandler);
  • 30.