forget the web

78
F**get the Web http://flic.kr/p/8JS7km

Upload: remy-sharp

Post on 17-May-2015

2.028 views

Category:

Technology


0 download

DESCRIPTION

Using the la

TRANSCRIPT

Page 1: Forget the Web

F**get the Webhttp://flic.kr/p/8JS7km

Page 2: Forget the Web
Page 3: Forget the Web

http://flic.kr/p/8Tsj3N

Page 4: Forget the Web

http://flic.kr/p/a25FHi

Page 5: Forget the Web

http://ftw.nodester.com

Page 6: Forget the Web

http://ftw.nodester.com

This is live now

Change this to yourTwitter username

Page 7: Forget the Web

http://ftw.nodester.com

Page 8: Forget the Web

http://flic.kr/p/5rTP9f

Page 9: Forget the Web

•Web Storage

• IndexedDB (where available)

•Web SQL Databases

•History API

•Offline manifesthttp://flic.kr/p/5rTP9f

Page 10: Forget the Web

http://flic.kr/p/4HYNgX

Page 11: Forget the Web

๏ Web Storage simple, and well supported IE8+

๏ Web SQL has good mobile support, but no Firefox

๏ IndexedDB gives us coverage

http://flic.kr/p/4HYNgX

Page 12: Forget the Web

Web Storage

Page 13: Forget the Web

Cookies suck.

Page 14: Forget the Web

Cookies suck.Not the edible kind, duh!

Page 15: Forget the Web

1. Code for cookies difficult2. Date format is fugly3. Limitations in size and number4. Deleting doesn't really delete5. Sessions leak...but not always!

Page 16: Forget the Web

Fuck cookies.

http://flic.kr/p/5irsCG

Page 17: Forget the Web

Sexy Storage FTW

http://flic.kr/p/3pBDzf

Page 18: Forget the Web

•localStorage no expiry required & persists

•sessionStorage doesn't leak

•Applied to document origin, i.e. scheme/host/port tuple

•Insanely simple API

Page 19: Forget the Web

setItem(key, value)

removeItem(key)

length

key(index)

clear()

Page 20: Forget the Web

var store = localStorage;store.name = 'remy';

Page 21: Forget the Web

var store = localStorage;store.name = 'remy';delete store.name;

Page 22: Forget the Web

Values are coerced in to strings

Page 23: Forget the Web

Values are coerced in to strings

Work around: JSON(and http://www.json.org/json2.js)

Page 24: Forget the Web

Events Too

Page 25: Forget the Web

The API isn't protected, you can, if you want to mess things up, do:

localStorage.key = 'foo';

Now the key method is a string :(

Gotcha

Page 26: Forget the Web

Web SQL Databases

http://flic.kr/p/drmCJ

Page 27: Forget the Web

๏ SQLite based

๏ No longer actively maintained

๏ Good Safari support - i.e. iOS

๏ Fully featured debuggers available

Page 28: Forget the Web

db = openDatabase('Notes', '1.0', 'notes', 5242880);

db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS ' + 'notes(id TEXT PRIMARY KEY ASC, title TEXT, ' + 'rating INTEGER, date DATE, notes TEXT, ' + 'updated DATE, url TEXT UNIQUE)', [], // fields success, error);});

Page 29: Forget the Web

db = openDatabase('Notes', '1.0', 'notes', 5242880);

db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS ' + 'notes(id TEXT PRIMARY KEY ASC, title TEXT, ' + 'rating INTEGER, date DATE, notes TEXT, ' + 'updated DATE, url TEXT UNIQUE)', [], // fields success, error);});

Page 30: Forget the Web

db = openDatabase('Notes', '1.0', 'notes', 5242880);

db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS ' + 'notes(id TEXT PRIMARY KEY ASC, title TEXT, ' + 'rating INTEGER, date DATE, notes TEXT, ' + 'updated DATE, url TEXT UNIQUE)', [], // fields success, error);});

Page 31: Forget the Web

db = openDatabase('Notes', '1.0', 'notes', 5242880);

db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS ' + 'notes(id TEXT PRIMARY KEY ASC, title TEXT, ' + 'rating INTEGER, date DATE, notes TEXT, ' + 'updated DATE, url TEXT UNIQUE)', [], // fields success, error);});

Page 32: Forget the Web

db = openDatabase('Notes', '1.0', 'notes', 5242880);

db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS ' + 'notes(id TEXT PRIMARY KEY ASC, title TEXT, ' + 'rating INTEGER, date DATE, notes TEXT, ' + 'updated DATE, url TEXT UNIQUE)', [], // fields success, error);});

Field values map to '?' values in the SQL

Page 33: Forget the Web

db = openDatabase('Notes', '1.0', 'notes', 5242880);

db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS ' + 'notes(id TEXT PRIMARY KEY ASC, title TEXT, ' + 'rating INTEGER, date DATE, notes TEXT, ' + 'updated DATE, url TEXT UNIQUE)', [], // fields success, error);});

Page 34: Forget the Web

๏ Atomic transactions

๏ Queues every request

๏ Good Safari support - i.e. iOS

๏ Fully featured debuggers available

Page 35: Forget the Web

IndexedDB

http://flic.kr/p/5KXFwB

Page 36: Forget the Web

• Still very new

• Support will be further reaching than Web SQL (but unsure about Safari)

• Very, very difficult to debug atm.

Page 37: Forget the Web

var request = indexedDB.open('notes');request.onerror = fail;request.onsuccess = function (e) { db = e.target.result;};

Very, very object event based.

Page 38: Forget the Web

var setVRequest = db.setVersion(v);setVRequest.onsuccess = function () { var store = db.createObjectStore( 'notes', {keyPath: 'id'}); success(); // your callback};

Now create the actual data store

Page 39: Forget the Web

var RW = IDBTransaction.READ_WRITE;

var transaction = db.transaction(['notes'], RW, 0), store = transaction.objectStore('notes'), request = store.put(data);

Get the object store and put in it

Page 40: Forget the Web

var RW = IDBTransaction.READ_WRITE;

var transaction = db.transaction(['notes'], RW, 0), store = transaction.objectStore('notes'), request = store.get(id); request.onsuccess = function (event) { callback(event.target.result);};

On success, result is in event.target

Page 41: Forget the Web

Lawnchairhttp://westcoastlogic.com/lawnchair/

Page 42: Forget the Web

History API

http://flic.kr/p/a42tLM

Page 43: Forget the Web
Page 44: Forget the Web
Page 45: Forget the Web

function router(path) { if (path.indexOf('/conf') === 0) { showConferenceDetails(path.substr(5)); } else if (path === '/about') { body.id = ''; body.className = 'about'; } else if (path === '/') { showConferences('next'); } else { showConferences(path.substr(1)); }}

Page 46: Forget the Web

function router(path) { if (path.indexOf('/conf') === 0) { showConferenceDetails(path.substr(5)); } else if (path === '/about') { body.id = ''; body.className = 'about'; } else if (path === '/') { showConferences('next'); } else { showConferences(path.substr(1)); }}

Page 47: Forget the Web

router(location.pathname);

Page 48: Forget the Web

History APIhistory.pushState(state,title,url);

window.onpopstate = fn;

Page 49: Forget the Web

link.onclick = function (event) { event.preventDefault(); showConferenceDetails(this.path); history.pushState('', '', this.path);};

Page 50: Forget the Web

link.onclick = function (event) { event.preventDefault(); showConferenceDetails(this.path); history.pushState('', '', this.path);};

Page 51: Forget the Web

link.onclick = function (event) { event.preventDefault(); showConferenceDetails(this.path); history.pushState('', '', this.path);};

Page 52: Forget the Web

link.onclick = function (event) { event.preventDefault(); showConferenceDetails(this.path); history.pushState('', '', this.path);};

Page 53: Forget the Web

link.onclick = function (event) { event.preventDefault(); showConferenceDetails(this.path); history.pushState('', '', this.path);};

Page 54: Forget the Web

link.onclick = function (event) { event.preventDefault(); showConferenceDetails(this.path); history.pushState('', '', this.path);};

Now our url matches the page

Page 55: Forget the Web

window.onpopstate = function () { router(location.pathname);};

Page 56: Forget the Web

URLs FTW!

http://flic.kr/p/a42tLM

Page 57: Forget the Web

What about when they request a URL that doesn't exist???

Page 58: Forget the Web

Offline

http://flic.kr/p/8zrMy8

Page 59: Forget the Web
Page 60: Forget the Web

<html manifest="myapp.appcache">

Page 61: Forget the Web

<html manifest="myapp.appcache">

Serve with text/manifest

Page 62: Forget the Web

<html manifest="myapp.appcache">

Serve with text/manifest

Set header cache-control: no-cache

Page 63: Forget the Web

<html manifest="myapp.appcache">

Serve with text/manifest

Set header cache-control: no-cache

starts with CACHE MANIFEST

Page 64: Forget the Web

CACHE MANIFEST

/range.jsdatastore.js

Page 65: Forget the Web
Page 66: Forget the Web

chrome://appcache-internals

Page 67: Forget the Web

CACHE MANIFEST

/index.htmlrange.jsdatastore.js

FALLBACK:# force everything through # the index url/ /

# this won't match # anything unless it's on # another domainNETWORK:*

# v4

Page 68: Forget the Web

CACHE MANIFEST

/index.htmlrange.jsdatastore.js

FALLBACK:# force everything through # the index url/ /

# this won't match # anything unless it's on # another domainNETWORK:*

# v4

Served from cache

Page 69: Forget the Web

CACHE MANIFEST

/index.htmlrange.jsdatastore.js

FALLBACK:# force everything through # the index url/ /

# this won't match # anything unless it's on # another domainNETWORK:*

# v4

Requests for files not

found in the cache, are

directed to /

i.e. index.html

(when offline).

Page 70: Forget the Web

CACHE MANIFEST

/index.htmlrange.jsdatastore.js

FALLBACK:# force everything through # the index url/ /

# this won't match # anything unless it's on # another domainNETWORK:*

# v4

Any requests to urls

that don't match / -

i.e. on another

domain, will be

served through the

web.

Page 71: Forget the Web

CACHE MANIFEST

/index.htmlrange.jsdatastore.js

FALLBACK:# force everything through # the index url/ /

# this won't match # anything unless it's on # another domainNETWORK:*

# v4

Also ensures

browser even

attempts to load the

asset

Page 72: Forget the Web

CACHE MANIFEST

/index.htmlrange.jsdatastore.js

FALLBACK:# force everything through # the index url/ /

# this won't match # anything unless it's on # another domainNETWORK:*

# v4

The contents of the

manifest must

change to trigger an

update

Page 73: Forget the Web

/future

/And let the router code

handle the path

Page 74: Forget the Web

CACHE MANIFEST

/index.htmlrange.jsdatastore.js

FALLBACK:# force everything through # the index url/ /

# this won't match # anything unless it's on # another domainNETWORK:*

# v4

Requests for files not

found in the cache, are

directed to /

i.e. index.html

(when offline).

Page 75: Forget the Web

http://flic.kr/p/5rTP9f

Page 76: Forget the Web

• Web Storage for simple data

• Larger data in IndexedDB & Web SQL

• History for back button and url

• Offline to support our fake urls

http://flic.kr/p/5rTP9f

Page 77: Forget the Web

http://ftw.nodester.com

Page 78: Forget the Web

Thank you.http://flic.kr/p/8JS7km