forked from cfjedimaster/html5-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preso.html
527 lines (464 loc) · 14 KB
/
preso.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
<!doctype html>
<html>
<head>
<title>HTML5 Storage</title>
<link href="http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="revealjs/css/reset.css">
<link rel="stylesheet" href="revealjs/css/main.css">
<link rel="stylesheet" href="revealjs/lib/css/zenburn.css">
<link rel="stylesheet" href="revealjs/css/print.css" type="text/css" media="print">
<style>
html.intro body {
background:url("images/raiders_warehouse.jpg");
background-position:center;
background-size: 100%;
}
html.wrapup body {
background:url("images/swthrone.jpg");
background-position:center;
background-size: 100% 100%;
background-repeat: no-repeat;
}
html.intro h1, html.intro p {
background-color: rgba(0,0,0,0.7);
}
iframe {
width: 700px;
height: 320px;
}
dl {
text-align: left;
}
dt {
font-weight: bold;
}
dd {
margin-left: 50px;
margin-right: 50px;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-state="intro">
<h1>HTML5 Storage</h1>
<p>
by Raymond Camden
</p>
</section>
<section>
<h2>This Guy</h2>
<ul style="float:left">
<li>Raymond Camden</li>
<li>Developer Evangelist for Adobe</li>
<li>Blogging at raymondcamden.com</li>
<li>Tweeting at @cfjedimaster</li>
</ul>
<p/>
<img src="images/ray.png">
</section>
<section>
<h2>Warning...</h2>
<ul>
<li>Lot's of code....</li>
<li>You can download the code (and these slides) and play with it</li>
<li>github.com/cfjedimaster/html5-storage</li>
<li>jQuery fanboy in effect</li>
</ul>
</section>
<section>
<h2>Why store anything?</h2>
<ul>
<li>HTTP can be expensive</li>
<li>Sometimes data doesn't change</li>
<li>Connections sometimes aren't</li>
</ul>
<aside class="notes">
HTTP isn't too expensive, obviously, since we use it all day long. But when you
take a fancy Ajax Web 3.0 app doing 10-20 different HTTP requests in the back end,
it can add up quickly. Consider mentioning LighthousePro experience.
Your data may change rarely. For example, your company's offices.
Guess what - sometimes your offline.
</aside>
</section>
<section>
<h2>The Game Plan</h2>
<ul>
<li>Talk about the technology</li>
<li>Going to show you some demos</li>
<li>Show you the support matrix</li>
</ul>
<p class="fragment">
<img src="images/muhahaha.jpg">
</p>
<aside class="notes">
I cannot stress enough: You need to stop thinking about HTML5 features are binary.
Even if 80% of your audience can't use a feature, you can provide incredible value to
20% with an small amount of effort. Those 20% can turn around and help you get more
customers.
Consider: Geoposition+Store example
</aside>
</section>
<section>
<h2>The Technologies</h2>
<ul>
<li>Cookies (no, really)</li>
<li>Local/Session Storage</li>
<li>WebSQL</li>
<li>IndexedDB</li>
<li>FileSystem API</li>
</ul>
<aside class="notes">
Maybe mention offline support since it could possible be considered storage.
</aside>
</section>
<section>
<h2>Cookies</h2>
<ul>
<li>Oldest and probably the safest</li>
<li>Read/Write on both client and server (*)</li>
<li>Reread the above - it gets sent back and forth</li>
<li>Limited on both sides in terms of count/individual size</li>
<li>Simple values, but you could encode</li>
</ul>
</section>
<section>
<h2>Cookies - Possible Uses?</h2>
<ul>
<li>Authentication/Authorization</li>
<li>Preferences that the server needs to know</li>
</ul>
</section>
<section>
<h2>Cookies - How Many?</h2>
<ul>
<li>According to the <a href="http://www.ietf.org/rfc/rfc2109.txt">spec:</a> (Feb 1997)</li>
<li>At least 300 cookies (per browser)</li>
<li>At least 4096 bytes per cookie</li>
<li>At least 20 per unique host</li>
<li class="fragment"><strong>No</strong> good way to handle rejection</li>
</ul>
</section>
<section>
<h2>Cookies - Example</h2>
<pre><code>
//set with...
document.cookie="key=value;args..";
//read with...
console.log(document.cookie);
</code></pre>
</section>
<section>
<h2>Cookies - Demo</h2>
<img src="images/Stop-Hammer-Time.jpg">
</section>
<section>
<h2>Cookies - When can I use it?</h2>
<p>
Everywhere! <sup>*</sup>
</p>
</section>
<section>
<h2>LocalStorage (aka DOM Storage)</h2>
<ul>
<li>API to set name/value pairs, remove items</li>
<li>You can also directly get/set</li>
<li>Simple values (JSON FTW)</li>
<li>Totally stored on the client only</li>
<li>Session based version</li>
<li><a href="http://www.w3.org/TR/webstorage/">Spec</a></li>
</ul>
</section>
<section>
<h2>LocalStorage - Possible Uses?</h2>
<ul>
<li>Preferences your server doesn't need to know</li>
<li>Search history</li>
<li>"Favorited" content items</li>
<li>User "State" vs User "Storage" (credit: Ido Green)</li>
<!--
As a reminder to myself, the idea is that you can save 'state' as in form values, etc.
Storage implies lots of ad hoq data
-->
</ul>
</section>
<section>
<h2>LocalStorage - How Many?</h2>
<ul>
<li>2.49 Megs total - on average</li>
<li>Details here: <a href="http://dev-test.nemikor.com/web-storage/support-test/" target="_new">http://dev-test.nemikor.com/web-storage/support-test/</a></li>
</ul>
</section>
<section>
<h2>LocalStorage - Example</h2>
<pre><code>
//API way
localStorage.setItem("name", "value");
var x = localStorage.getItem("name");
localStorage.removeItem("name");
localStorage.clear();
//Non API way
localStorage["name"] = "value";
var x = localStorage["name"];
delete localStorage["name"];
for(var x in localStorage) delete localStorage[x];
</code></pre>
</section>
<section>
<h2>LocalStorage - Demo</h2>
<img src="images/Stop-Hammer-Time.jpg">
</section>
<section>
<h2>LocalStorage - FYI</h2>
<ul>
<li>Chrome Dev Tools (view/edit)</li>
<li>LocalStorage Monitor (<a href="https://chrome.google.com/webstore/detail/bpidlidmmmnapeldonddkjmmjkpeiabi">chrome web store</a>)</li>
<li>There <i>is</i> an event - but it is wonky (test4.html)</li>
</ul>
</section>
<section>
<h2>LocalStorage - When can I use it?</h2>
<iframe src="http://caniuse.com/namevalue-storage/embed"></iframe>
</section>
<section>
<h2>WebSQL</h2>
<ul>
<li>Know SQL? You can use WebSQL</li>
<li>"Mini" file-based database (SQLite) in your browser</li>
<li>You can open a database, run SQL, even use transactions</li>
<li>Asynchronous</li>
<li><a href="http://www.w3.org/TR/webdatabase/">Spec</a></li>
</ul>
</section>
<section>
<h2>WebSQL - Possible Uses?</h2>
<ul>
<li>Storing a <i>lot</i> of content</li>
<li>Storing content you want to search</li>
</ul>
</section>
<section>
<h2>WebSQL - How Many/How Big?</h2>
<ul>
<li>5 megs</li>
<li>User may be prompted for more</li>
</ul>
</section>
<section>
<h2>WebSQL - Example</h2>
<pre><code>
db = window.openDatabase("name","1","nice name",5*1024*1024);
db.readTransaction(function(tx) {
tx.executeSql("select id,title from notes", [],
function(tx, results) {
for(var i=0, len=results.rows.length; i<len;i++) {
var row = results.rows.item(i);
console.log(i+" id="+row.id+" title="+row.title);
}
}
}
</code></pre>
</section>
<section>
<h2>WebSQL - Demo</h2>
<img src="images/Stop-Hammer-Time.jpg">
</section>
<section>
<h2>WebSQL - FYI</h2>
<ul>
<li>Chrome Dev Tools (view/edit)</li>
<li>And yeah - run arbitrary SQL</li>
</ul>
</section>
<section>
<h2>WebSQL - When can I use it?</h2>
<iframe src="http://caniuse.com/sql-storage/embed"></iframe>
</section>
<section>
<h2>IndexedDB</h2>
<ul>
<li>Storage for "significant amounts of structured data" (source: MDN)</li>
<li>More "free form" storage than WebSQL</li>
<li>Uses an Index based API</li>
<li>Asynchronous + Transaction</li>
<li><a href="http://www.w3.org/TR/IndexedDB/">Spec</a></li>
</ul>
</section>
<section>
<h2>IndexedDB - How Many/How Big?</h2>
<ul>
<li>50 megs</li>
<li>User may be prompted for more</li>
</ul>
</section>
<section>
<h2>IndexedDB - Index wha???</h2>
<ul>
<li>Getting values can be done by key (think primary key)</li>
<li>You can make an index on (most) any property</li>
<li>And by range (think list) on an index</li>
<li>No free form search ala SQL</li>
<li>So I can do "CamA to CamB" but not "CaXden"</li>
</ul>
</section>
<section>
<h2>IndexedDB - Creation is Tricky</h2>
<ul>
<li>You can only change structure by changing version</li>
<li>If a user had version 1 and you're on version 3, you have to maintain the code to update between them</li>
<li>So yeah, get it right the first time</li>
<li><strike>And oh yeah - Chrome doesn't work right yet</strike></li>
</ul>
<img src="images/confusing_signs11.jpg">
</section>
<section>
<h2>IndexedDB - Basic Terms</h2>
<dl>
<dt>key</dt>
<dd>The primary key, can be autogenerated</dd>
<dt>objectstore</dt>
<dd>One set of data. Think table.</dd>
<dt>index</dt>
<dd>A way to get at the data and there can be more than one per object</dd>
<dt>cursor</dt>
<dd>A way to iterate over objects</dd>
<dt>key range</dt>
<dd>A way to specify a range of keys to be returned</dd>
</dl>
</section>
<section>
<h2>IndexedDB - Demo</h2>
<img src="images/Stop-Hammer-Time.jpg">
</section>
<section>
<h2>IndexedDB - FYI</h2>
<ul>
<li>Chrome Dev Tools (view)</li>
</ul>
</section>
<section>
<h2>IndexedDB - When can I use it?</h2>
<iframe src="http://caniuse.com/indexeddb/embed"></iframe>
</section>
<section>
<h2>Just in case you missed it...</h2>
<ul>
<li>WebSQL - great mobile support (all iOS, all Android)</li>
<li>IndexedDB - no mobile support (iOS6 maybe, or Jelly Bean for all 2 of you)</li>
</ul>
<p class="fragment">
<img src="images/face_palm_by_dancerher.jpg">
<!-- Credit: http://dancerher.deviantart.com/art/face-palm-160020379 -->
</p>
</section>
<section>
<h2>FileSystem</h2>
<ul>
<li>Not the File API (<a href="http://www.w3.org/TR/FileAPI/">spec</a>), but we use it</li>
<li>A sandbox for temporary/persistent file storage</li>
<li>Asynchronous API for reading/writing/deleting directories and files</li>
<li>Basic quota API (required for persistent storage)</li>
<li><a href="http://www.w3.org/TR/file-system-api/">Spec</a></li>
</ul>
</section>
<section>
<h2>FileSystem - Possible Uses?</h2>
<ul>
<li>Storing binary resources for games/apps</li>
<li>Storing drag/dropped files</li>
</ul>
</section>
<section>
<h2>FileSystem - How Big?</h2>
<ul>
<li>Ask the Quota API and good luck with that</li>
<li>User will be prompted for persistent storage</li>
<li>User is then prompted for more storage</li>
<li>No way to disable it</li>
</ul>
</section>
<section>
<h2>What you can do</h2>
<ul>
<li>Create a directory</li>
<li>List the contents of a directory</li>
<li>Remove a directory recursively</li>
<li>Create a file</li>
<li>Get file metadata</li>
<li>Remove a file</li>
<li>Copy or move a file</li>
</ul>
</section>
<section>
<h2>FileSystem Key Objects</h2>
<ul>
<li>FileSystem</li>
<li>DirectoryReader</li>
<li>DirectoryEntry</li>
<li>FileReader</li>
<li>FileWriter</li>
<li>FileEntry</li>
</ul>
</section>
<section>
<h2>FileSystem - Demo</h2>
<img src="images/Stop-Hammer-Time.jpg">
<aside class="notes">
http://www.adobe.com/devnet/html5/articles/real-world-example-html5-filesystem-api.html
</aside>
</section>
<section>
<h2>FileSystem - FYI</h2>
<ul>
<li>HTML5 File System Explorer (<a href="https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CGsQFjAA&url=https%3A%2F%2Fchrome.google.com%2Fwebstore%2Fdetail%2Fnhnjmpbdkieehidddbaeajffijockaea&ei=IO4aUIyAHYWfiAK8poHACg&usg=AFQjCNE1pcsYhXfK-V9o5pElMHiL1d3vVA&sig2=e4jOczuBDEYuZHNZxTJOLg">link</a>)</li>
<li>Terminal (<a href="http://www.htmlfivewow.com/demos/terminal/terminal.html">link</a>)</li>
</ul>
</section>
<section>
<h2>FileSystem - When can I use it?</h2>
<iframe src="http://caniuse.com/filesystem/embed"></iframe>
</section>
<section data-state="wrapup">
<h1>Wrap Up</h1>
</section>
<section>
<h2>Useful Resources</h2>
<ul>
<li>developer.mozilla.org</li>
<li>webplatform.org</li>
<li>html5rocks.com</li>
<li>diveintohtml5.info</li>
<li>html5bookmarks.com</li>
</ul>
</section>
<section>
<h2>Questions?</h2>
<ul>
<li>email: raymondcamden@gmail.com</li>
<li>web: raymondcamden.com</li>
<li>stupid crap: @cfjedimaster</li>
</ul>
<img src="images/kirk-yelling-kahn.jpg" title="Why include Kirk? Because Kirk is awesome.">
</section>
</div>
</div>
<script src="revealjs/js/reveal.js"></script>
<script src="revealjs/lib/js/highlight.js"></script>
<script>
Reveal.initialize({
progress:false,
theme:"default",
history:true
});
hljs.initHighlightingOnLoad();
Reveal.addEventListener( 'slidechanged', function( event ) {
// event.previousSlide, event.currentSlide, event.indexh, event.indexv
var notes = event.currentSlide.querySelector(".notes");
if(notes) {
console.info(notes.innerHTML.replace(/\n\s+/g,'\n'));
}
} );
</script>
</body>
</html>