Client-side storage

56
Client-side Storage The Little Book Of (Mostly) Everything Friday, April 26, 13

description

An overview of client-side (browser) technologies

Transcript of Client-side storage

Page 1: Client-side storage

Client-side Storage

The Little Book Of (Mostly) Everything

Friday, April 26, 13

Page 2: Client-side storage

About me

Ruben Tan

VPE of OnApp CDN KL

Aspiring Javascript Samurai

@roguejs

http://roguejs.com

https://github.com/soggie

Friday, April 26, 13

Page 3: Client-side storage

CATS!!!!!

Friday, April 26, 13

Page 4: Client-side storage

About me

Friday, April 26, 13

Page 5: Client-side storage

About me

Worked with Java 6+ years

Friday, April 26, 13

Page 6: Client-side storage

About me

Worked with Java 6+ years

Adopted node.js, redis & CouchDB

Friday, April 26, 13

Page 7: Client-side storage

About me

Worked with Java 6+ years

Adopted node.js, redis & CouchDB

Huge fan of Javascript & related technologies

Friday, April 26, 13

Page 8: Client-side storage

About me

Worked with Java 6+ years

Adopted node.js, redis & CouchDB

Huge fan of Javascript & related technologies

Organizer of NodeHack

Friday, April 26, 13

Page 9: Client-side storage

About me

Worked with Java 6+ years

Adopted node.js, redis & CouchDB

Huge fan of Javascript & related technologies

Organizer of NodeHack

Dabbled in 0MQ and various messaging techs

Friday, April 26, 13

Page 10: Client-side storage

About me

Worked with Java 6+ years

Adopted node.js, redis & CouchDB

Huge fan of Javascript & related technologies

Organizer of NodeHack

Dabbled in 0MQ and various messaging techs

Working on a auto-devenv provisioner with vagrant and puppet

Friday, April 26, 13

Page 11: Client-side storage

HTTP & Browser State

COOKIES:

HTTP by nature is stateless

1994 - web cookies created (in Netscape) for e-commerce (carts)

Cookies became de-facto browser-side store

Inefficient because cookies are included in every request

Friday, April 26, 13

Page 12: Client-side storage

HTTP & Browser State

Cookies inefficient and insecure

Sessions stored on server side became standard

Then HTML5 came along...

Friday, April 26, 13

Page 13: Client-side storage

Case Studies

Friday, April 26, 13

Page 14: Client-side storage

Case Studies

Synchronizing data across tabs

Friday, April 26, 13

Page 15: Client-side storage

Case Studies

Synchronizing data across tabs

Reduce server load by minimizing polling

Friday, April 26, 13

Page 16: Client-side storage

Case Studies

Synchronizing data across tabs

Reduce server load by minimizing polling

Historic immutable data (analytics, history, etc)

Friday, April 26, 13

Page 17: Client-side storage

Case Studies

Synchronizing data across tabs

Reduce server load by minimizing polling

Historic immutable data (analytics, history, etc)

Simplify data sync between frontend & backend

Friday, April 26, 13

Page 18: Client-side storage

Case Studies

Synchronizing data across tabs

Reduce server load by minimizing polling

Historic immutable data (analytics, history, etc)

Simplify data sync between frontend & backend

Persisting form data in complex forms

Friday, April 26, 13

Page 19: Client-side storage

Case Studies

Synchronizing data across tabs

Reduce server load by minimizing polling

Historic immutable data (analytics, history, etc)

Simplify data sync between frontend & backend

Persisting form data in complex forms

etc

Friday, April 26, 13

Page 20: Client-side storage

Example:

Server

Tab 1 Tab 2

Poll Poll

Friday, April 26, 13

Page 21: Client-side storage

Example:

Server

Tab 1 Tab 2

Update Push

Friday, April 26, 13

Page 22: Client-side storage

Example:

Server

Tab 1 Tab 2

Update

Update

Store

Read/Auto

SERVER

BROWSER

Friday, April 26, 13

Page 23: Client-side storage

Client-side Overview

Web Storage

Web SQL Database

Indexed Database

File Access

Friday, April 26, 13

Page 24: Client-side storage

Web Storage

http://dev.w3.org/html5/webstorage/

Protocol to store data in browser across tabs

Improvement on cookies

Comes in two flavors:

localStorage - forever

sessionStorage - until end of browser session

No support for transactions

Friday, April 26, 13

Page 25: Client-side storage

Web Storage Support

Friday, April 26, 13

Page 26: Client-side storage

Web SQL Database

Bringing SQL to client-side storage, based on sqlite

Developers love it

Browser makers hated it

W3C abandoned it in November 2010

Friday, April 26, 13

Page 27: Client-side storage

Web SQL Support

Friday, April 26, 13

Page 28: Client-side storage

Indexed Database

Proposed by Oracle in 2009

Web Storage on steroids

Assumes data stored is an object, with an index

Allows queries via the indices

Friday, April 26, 13

Page 29: Client-side storage

Indexed Database Support

Friday, April 26, 13

Page 30: Client-side storage

File API

Let’s you save files in the browser

Friday, April 26, 13

Page 31: Client-side storage

File Access Support

Friday, April 26, 13

Page 32: Client-side storage

Limitations of Client Storage

Friday, April 26, 13

Page 33: Client-side storage

Limitations of Client Storage

Cookies = 4kb each

Friday, April 26, 13

Page 34: Client-side storage

Limitations of Client Storage

Cookies = 4kb each

localStorage = 2.5 ~ 5MB average

Friday, April 26, 13

Page 35: Client-side storage

Limitations of Client Storage

Cookies = 4kb each

localStorage = 2.5 ~ 5MB average

IndexedDB = up to 20% of available space

Friday, April 26, 13

Page 36: Client-side storage

Limitations of Client Storage

Cookies = 4kb each

localStorage = 2.5 ~ 5MB average

IndexedDB = up to 20% of available space

FileAPI = same as IndexedDB

Friday, April 26, 13

Page 37: Client-side storage

Moar Limitations!!

Friday, April 26, 13

Page 38: Client-side storage

Moar Limitations!!

Data-types to store:

Friday, April 26, 13

Page 39: Client-side storage

Moar Limitations!!

Data-types to store:

Cookie: STRING

Friday, April 26, 13

Page 40: Client-side storage

Moar Limitations!!

Data-types to store:

Cookie: STRING

Web Storage: STRING

Friday, April 26, 13

Page 41: Client-side storage

Moar Limitations!!

Data-types to store:

Cookie: STRING

Web Storage: STRING

Indexed Database: JS OBJECT

Friday, April 26, 13

Page 42: Client-side storage

Moar Limitations!!

Data-types to store:

Cookie: STRING

Web Storage: STRING

Indexed Database: JS OBJECT

File: BINARY

Friday, April 26, 13

Page 43: Client-side storage

Moving on...

Browsers and W3C sees the need for client-side storage

Web Store + IndexedDB + File API = an almost complete solution

Where does this leave us?

Friday, April 26, 13

Page 44: Client-side storage

The Emerging Scene

Google Gears (sadly, is dead)

Synckit

Store.js

Garlic.js - form persistence

PouchDB (based on CouchDB) - auto-sync with couchDB

jQuery plugins

db.js

LocalStorageDB

Lawnchair

ydn-db - unifying indexedDB, webSQL and webStorage

Friday, April 26, 13

Page 45: Client-side storage

Client-side Storage Challenges

Friday, April 26, 13

Page 46: Client-side storage

Client-side Storage Challenges

Limited amount of resources

Friday, April 26, 13

Page 47: Client-side storage

Client-side Storage Challenges

Limited amount of resources

Must be as lightweight as possible

Friday, April 26, 13

Page 48: Client-side storage

Client-side Storage Challenges

Limited amount of resources

Must be as lightweight as possible

Focuses more on querying of data vs. storage mechanism

Friday, April 26, 13

Page 49: Client-side storage

Client-side Storage Challenges

Limited amount of resources

Must be as lightweight as possible

Focuses more on querying of data vs. storage mechanism

Security, consistency, performance

Friday, April 26, 13

Page 50: Client-side storage

Client-side Storage Challenges

Limited amount of resources

Must be as lightweight as possible

Focuses more on querying of data vs. storage mechanism

Security, consistency, performance

Javascript. Duuuddeeeee....

Friday, April 26, 13

Page 51: Client-side storage

What can we do?

Friday, April 26, 13

Page 52: Client-side storage

What can we do?

Observe the scene (PouchDB & ydn-db)

Friday, April 26, 13

Page 53: Client-side storage

What can we do?

Observe the scene (PouchDB & ydn-db)

Incorporate into major frameworks (backbone, ember, angular, KO, etc)

Friday, April 26, 13

Page 54: Client-side storage

What can we do?

Observe the scene (PouchDB & ydn-db)

Incorporate into major frameworks (backbone, ember, angular, KO, etc)

Simplify and standardize API

Friday, April 26, 13

Page 55: Client-side storage

What can we do?

Observe the scene (PouchDB & ydn-db)

Incorporate into major frameworks (backbone, ember, angular, KO, etc)

Simplify and standardize API

Understanding the power of client-side offloading

Friday, April 26, 13

Page 56: Client-side storage

That’s all folks!

Friday, April 26, 13