A brief history of client-side storage followed by a more in-depth review of Web Storage, Web SQL Database and Indexed Database before concluding with a look towards the Filesystem API
client-side storage followed by a more in-depth review of Web Storage, Web SQL Database and Indexed Database before concluding with a look towards the Filesystem API Philip Battle https://mailtrack.io/
the web browser a memory.” Javascript: The Definitive Guide, O’Reilly • Allows for the retention of state between the client and server • Data is stored on the user's hard drive • Stores basic user preferences or even a web apps complete state (think offline Gmail)
• Reliable • Session or persistent ! ! Disadvantages! • Store only very small amounts of string data (4k) • Travel from browser to server with every HTTP request • Vulnerable to attack • Awkward JavaScript API • Synchronous
for storing data in a database within the browser. The spec defines an API on top of the standard SQLite 3.1.19 database, which uses a single file to store data.
side applications • Webkit support • The user interface will ask permission scale up the database size: 5, 10, 50, 100 and 500MB etc. • Good search performance • Asynchronous Disadvantages! • Abandoned by standards authority • Vendors likely to drop support • SQL doesn't seem appropriate for client-side development • Rigid lacking agility since schema must be defined upfront
window.addEventListener('storage', function(event) { var key = event.key; var oldValue = event.oldValue; var newValue = event.newValue; var url = event.url; // Address of the page var storageArea = event.storageArea; ! // Handle event });
Simple API • Session or persistent • Event model • Pollyfills Disadvantages! • Store only ~5Mb • Unstructured data with no transactions, indexing or searching facilties • Synchronous • Poor performance for large/ complex data (lack of indexing)
is built on a transactional database model • The IndexedDB API is mostly asynchronous • IndexedDB is object-oriented • IndexedDB uses requests almost everywhere
! // Create an objectStore var objectStore = db.createObjectStore("customers",{ keyPath: "id" // The objects must have a unique property with the same name as the keyPath /* autoIncrement: true */ /* out-of-line key */ }); ! …
customers by name. We may have duplicates so we can't use a unique index. objectStore.createIndex("name", "name", {unique: false}); ! // Create an index to search customers by email. We want to ensure that no two customers have the same email, so use a unique index. objectStore.createIndex("email", "email", {unique: true}); ! …
objectStore.get("658-44-4444"); ! request.onsuccess = function(event) { // Get the old value that we want to update var data = request.result; ! // Update the value(s) in the object that you want to change data.age = 42; ! // Put this updated object back into the database. objectStore.put(data); };
event.target.result; ! if (cursor) { console.log("Name for id " + cursor.key + " is " + cursor.value.name); customers.push(cursor.value); cursor.continue(); // Ascending order } else { console.log("No more entries!"); } };
between "Philip" and "Anne", but not including "Anne" var boundKeyRange = IDBKeyRange.bound("Philip", "Anne", false, true); ! index.openCursor(boundKeyRange, "prev").onsuccess = function(event) { var cursor = event.target.result; ! if (cursor) { // Do something with the matches. cursor.continue(); } };
good browsers support • No limit on the database's size. The user interface will just ask permission for storing blobs bigger than 50 MB • Good performance (indexes) • Non blocking API Disadvantages! • The API is very new, complex, and subject to revision • Little support in older and mobile browsers • Difficult and largely impractical to create a IndexedDB polyfill • like any NoSQL store, data is unstructured which can lead to integrity issues
representation of a file system • The File System API can use different storage types • Browsers impose storage quotas • The File System API has asynchronous and synchronous versions • The File System API interacts with other APIs
files, so it's suitable for images, audio, video etc • Good performance, having an asynchronous API ! Disadvantages! • Very early standard. Only available in Chrome and Opera • No transaction support • No built-in search/indexing support