Quantcast
Channel: JavaScript – Jonathan Jeter
Viewing all articles
Browse latest Browse all 14

HTML5 Texas JavaScript Workshop – Client-Side Storage

$
0
0

HTML5TX JavaScript Workshop - Pamela FoxWeb technologies have taken a long time to progress.

A lot of the standards we see today are because browsers decided to implement new features.

HTML5 is now just supposed to be HTML. It is supposed to be a living standard.

Pamela needs an HTML app that helps choose her hair color.

Client-Side Storage

Cookies are used for all types of tracking, but they have issues with security, user trust (can be disabled), performance and size.

In the HTML spec, they considered the issues and came up with the following solutions.

localStorage

  • Key / value pairs – hash table
  • Persistent on page reloads
  • Avoids HTTP overhead of cookies
  • Great for storing user preferences (domain-specific, but it doesn’t matter where the script comes from)

sessionStorage

Same as localStorage but…

  • Lasts as long as browser is open (session-based)
  • Opening page in new window or tab starts new session
  • Great for sensitive data (e.g. banking sessions)

Why use a library for localStorage?

  • Support check
  • Serialization
  • Fallbacks
  • Specific use cases (Forms, expiration, etc)
  • Browser quirks (modern browser quirks, especially with mobile browsers)

localStorage libraries include store.js or lscache (presenter’s library).

Dangers of using localStorage are that localStorage access is synchronous and

  • JSON.parse/JSON.stringify takes CPU time

Recommendations:

  • Don’t serialize unnecessarily
  • Don’t use excessive keys
  • Don’t do excessive gets/sets
  • Don’t block the UI

Make sure to test for slow points BEFORE you start trying to improve performance. Time your site in target browsers and find the slow points - Blog post: Measuring performance in PhoneGapBlog post: Performance Profiling in JavaScriptJS Performance Analysis Tools. jsperf allows you to run tests and see the results of other people’s tests.

Don’t serialize unnecessarily

Don’t use excessive keys

Don’t do excessive gets/sets

Don’t block the UI

WORSE: A dysfunctional site

 

  • Don’t assume localStorage works or will always work.
  • Don’t use key names that collide.

IndexedDB

window.indexedDB

  • Object based data store
  • In-order retrieval by index or key
  • Asynchronous or synchronous API

This is going to be the standard, so it’s worth learning. Read more: Indexed DB specMDN: Using IndexedDB

IndexedDB: Why use a library?

  • Not the simplest API.
  • Many fundamental differences across browser versions.
  • Not supported in all browsers, fallbacks needed.

Storage library: Lawnchair

  • Includes serializationfallbacks (window.name, userData, gears, indexedDB)
  • Optional plugins for aggregationpagination, and queries.

Other IndexedDB Libraries

File APIs

There are many File APIs.

Probably going away or are going to change because IndexDB can do the same things.

SIDE NOTE: Marquee is coming back in CSS.

Which to Use?

Client-side Storage Comparison

Use Cases

  • Remember user data
  • Retain application state
  • Remember form input
  • Improve performance
  • Help the app work offline

Client-side Storage Course Elements

Here's what I think about , , , , , ,

What people are looking for when they find this page: Jonathan Jeter, angularjs indexeddb, contact interface expert jonathan, html5 expert advice, html5 webstore hash table, html5tx 2013 client side storage, UI to test datastorage API of html5, ydn-db et api


Viewing all articles
Browse latest Browse all 14

Trending Articles