Wed 09 Mar 2016

Storage

HTML provides some mechanisms for persisting data. Most of them are bad.

https://html.spec.whatwg.org/multipage/webstorage.html#storage

localStorage

/*global localStorage, sessionStorage*/
// Persists
localStorage.x = "blah";
// Cleared when browser closes
sessionStorage.y = "hello";

Synchronous only.

Strings only.

About 5MB per origin.

Should use it instead of cookies, because it doesn't get sent to the server (so, it's faster).

Probably not good enough for our purposes?

IndexedDB

It's an indexed key-value store.

  • Async
  • Transactional
  • Quick search

It's got some versioning, so that if you change the schema you can specify a function to handle the migration.

Maybe a little too new?

FileSystem

Too early.

It's a sandboxed file system.

WebSQL

Not supported in Firefox, IE. Deprecated.

Libraries

There's persist-js. Sounds a bit dodgy. Not really maintained any more.

Not sure what else.

Quotas

There is a quota API. It's not that widely used yet.

I need to know how much storage I'll have.

Async

Most of these have async APIs, which you can use.

SharedWorker

Poor support at the moment. Lets multiple web pages talk to the same worker. Interesting.

Offline Apps

Application Caching

I'm not really sure about this. You can specify some manifest file which says which things can be cached, and which must come from the network.

It's like normal browser caching, but still works if you're completely offline.