HTML5 Storage. Why Local Storage? Data accessed over the internet can never be as fast as accessing data locally Data accessed over internet not secure.

Slides:



Advertisements
Similar presentations
JavaScript and AJAX Jonathan Foss University of Warwick
Advertisements

New Tags, New Attributes, New JavaScript APIs, Forms, Validation, Audio, Video, SVG, Canvas Doncho Minkov Telerik Corporation
HTTP Request/Response Process 1.Enter URL ( in your browser’s address bar. 2.Your browser uses DNS to look up IP address of server.com.
In-browser storage and me Jason Casden North Carolina State University Libraries Code4Lib 2012.
PGN5: KAING, RISHER AND SCHULTE PERSISTENT COOKIES WITH BROWSER FINGERPRINTING.
Multiple Tiers in Action
Web Storage IDIA 619 Spring 2013 Bridget M. Blodgett.
 A cookie is a piece of text that a Web server can store on a user's hard disk.  Cookie data is simply name-value pairs stored on your hard disk by.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
Session: 11. © Aptech Ltd. 2HTML5 Audio and Video / Session 11  Describe the need for multimedia in HTML5  List the supported media types in HTML5 
Chapter 25 Utilizing Web Storage.
HTML 5 New Standardization of HTML. I NTRODUCTION HTML5 is The New HTML Standard, New Elements New Attributes Full CSS3 Support Video and Audio 2D/3D.
Martin Kruliš by Martin Kruliš (v1.0)1.
Ajax Basics The XMLHttpRequest Object. Ajax is…. Ajax is not…. Ajax is not a programming language. Ajax is not a programming language. Ajax is a methodology.
Ajax Application Errors Developer Oversight and Tracking Errors Presented by Eric Pascarello.
Principles of Computer Security: CompTIA Security + ® and Beyond, Third Edition © 2012 Principles of Computer Security: CompTIA Security+ ® and Beyond,
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
1 Accelerated Web Development Course JavaScript and Client side programming Day 2 Rich Roth On The Net
Client side web programming Introduction Jaana Holvikivi, DSc. School of ICT.
Chapter 8 Cookies And Security JavaScript, Third Edition.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Tutorial 10 Programming with JavaScript
CHAP 6. USING THE HTML5 WEB STORAGE API.  Cookie - Are a built-in way of sending text values back and forth from server to client.  Servers can use.
Using Client-Side Scripts to Enhance Web Applications 1.
Introduction to HTML. What is HTML?  Hyper Text Markup Language  Not a programming language but a markup language  Used for presentation and layout.
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Database Handling, Sessions, and AJAX. Post Back ASP.NET Functionality The IsPostBack method in ASP.NET is similar to the BlackBerry.refresh method –IsPostBack.
Creating Databases Local storage. join & split Classwork: show 1 table application. Share designs for oscars application. Adaptive select. Homework: [Catch.
Jim Janson. Agenda Evolution of software architectures 3-tier User interfaces Application servers Databases.
World Wide Web “WWW”, "Web" or "W3". World Wide Web “WWW”, "Web" or "W3"
1 3 Computing System Fundamentals 3.4 Networked Computer Systems.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
Tallahassee, Florida, 2015 COP4710 Database Systems Project Overview Fall 2015.
PHP A very brief introduction PHP1. PHP = PHP: Hypertext Processor A recursive acronym! PHP scripts are executed on the server side Executed by (a plugin.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
CS2550 Dr. Brian Durney. SOURCES  JavaScript: The Definitive Guide, by David Flanagan  Dive into HTML5, by Mark Pilgrim
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
IS2802 Introduction to Multimedia Applications for Business Lecture 8: JavaScript and Cookies Rob Gleasure
Rich Internet Applications 9. HTML 5 and RIAs. HTML 5 Standard currently under development by W3C Aims to improve the language with support for the latest.
JavaScript and Ajax (Internet Background) Week 1 Web site:
JQUERY AND AJAX
Generating XML Data from a Database Eugenia Fernandez IUPUI.
Phonegap Bridge – Storage CIS 136 Building Mobile Apps 1.
Some from Chapter 11.9 – “Web” 4 th edition and SY306 Web and Databases for Cyber Operations Cookies and.
Web Storage and Cookies Cookies, Local and Session Storage SoftUni Team Technical Trainers Software University
Data Storage in Android Димитър Н. Димитров. Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science.
Development of Internet Applications HTML5 Ing. Jan Janoušek 7.
Web Technologies Computing Science Thompson Rivers University
Creating Databases Local storage. join & split
Web Concepts Lesson 2 ITBS2203 E-Commerce for IT.
COP4710 Database Systems Project Overview.
Tutorial 10 Programming with JavaScript
JavaScript and Ajax (Internet Background)
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
CIS 136 Building Mobile Apps
What is Cookie? Cookie is small information stored in text file on user’s hard drive by web server. This information is later used by web browser to retrieve.
CSE 154 Lecture 22: AJAX.
WEB PROGRAMMING JavaScript.
ISC440: Web Programming 2 AJAX
CIS 136 Building Mobile Apps
HTML5 and Local Storage.
CSc 337 Lecture 27: Cookies.
CS4433 Database Systems Project.
HTML5 and Local Storage.
Web Technologies Computing Science Thompson Rivers University
CSc 337 Lecture 25: Cookies.
Presentation transcript:

HTML5 Storage

Why Local Storage? Data accessed over the internet can never be as fast as accessing data locally Data accessed over internet not secure HTML5 storage is on client

Persistent Local Storage Native client applications use operating system to store data such as preferences or runtime state Stored in registry, INI files, XML or other places using key/value pairs Web applications can’t do this

Cookies Invented early in Web’s history as a way to store persistent data (“magic cookies”) Small pieces of information about a user stored by Web server as text files on user’s computer Can be temporary or persistent

Cookies Included with every HTTP request – slows down application by transmitting same information repeatedly Sends unencrypted data over internet with every HTTP request Limited to 4KB data Example: filling out a text form field

Cookies not enough More storage space On the client Beyond page refresh Not transmitted to server

History IE: DHTML Behaviors userData behavior allowed 64K per domain Hierarchical XML-based structure Adobe Flash (2002) “Flash cookies” or Local Shared Objects Allows Flash objects to store 100K data per domain temporarily

History AMASS (AJAX Massive Storage System) Brad Neuberg Flash-to-JavaScript bridge Limited by Flash design quirks Flash 8: ExternalInterface (2006) Easier to access Local Shared Objects AMASS rewritten Integrated into Dojo Toolkit: dojox.storage 100KB storage Prompts user for exponentially increased storage

History Google: Gears (2007) Open source browser plug-in Provides additional capability in browsers (geolocation API in IE) API to embedded SQL database Unlimited data per domain in SQL database tables By 2009 dojox.storage could auto-detect and provide unified interface for Flash, Gears, Adobe AIR and early prototype of HTML5 storage (in older version of Firefox)

Previous Storage Solutions Either specific to single browser or relied on third party plug-in Different interfaces Different storage limitations Different user experiences

HTML5 Storage Provides standardized API Implemented natively Consistent across browsers HTML5 storage is a specification named “Web Storage” Previously part of HTML5 specifications Split into its own specification Different browsers may call it “Local Storage” or “DOM Storage”

Web Application Support Supported by latest version of all browsers! Access through localStorage object on global window object Before using, detect whether browser supports it IE 8+ Firefox 3.5+ Safari 4.0+ Chrome 4.0+ Opera IPhone 2.0+ Android 2.0+

Check for HTML5 Storage function supports_html5_storage() { try { return 'localStorage' in window && window['localStorage'] !== null; } catch (e) { return false; } }

if (Modernizr.localstorage) { // window.localStorage is available! } else { // no native support for HTML5 storage :( // maybe try dojox.storage or a third-party solution } Or use ModernizrModernizr

Using HTML5 Storage

localstorage object setItem( ) getItem( ) removeItem( ) clear( )

Using HTML5 Storage Tracking changes to the HTML5 storage area if (window.addEventListener) { window.addEventListener("storage", handle_storage, false); } else { window.attachEvent("onstorage", handle_storage); };

Using HTML5 Storage Tracking changes to the HTML5 storage area The handle_storage callback function will be called with a StorageEvent object, except in Internet Explorer where the event object is stored in window.event. function handle_storage(e) { if (!e) { e = window.event; } }

Using HTML5 Storage PROPERTYTYPEDESCRIPTION key stringthe named key that was added, removed, or modified oldValue any the previous value (now overwritten), or null if a new item was added newValue any the new value, or null if an item was removed url * stringthe page which called a method that triggered this change StorageEvent Object

Using HTML5 Storage Limitations in current browsers: 5 MB of storage from each origin.origin Can not ask user for more storage (except for Opera, sort of)

HTML5 in action

function saveGameState() { if (!supportsLocalStorage()) { return false; } localStorage["halma.game.in.progress"] = gGameInProgress; for (var i = 0; i < kNumPieces; i++) { localStorage["halma.piece." + i + ".row"] = gPieces[i].row; localStorage["halma.piece." + i + ".column"] = gPieces[i].column; } localStorage["halma.selectedpiece"] = gSelectedPieceIndex; localStorage["halma.selectedpiecehasmoved"] = gSelectedPieceHasMoved; localStorage["halma.movecount"] = gMoveCount; return true; }

function resumeGame() { if (!supportsLocalStorage()) { return false; } gGameInProgress = (localStorage["halma.game.in.progress"] == "true"); if (!gGameInProgress) { return false; } gPieces = new Array(kNumPieces); for (var i = 0; i < kNumPieces; i++) { var row = parseInt(localStorage["halma.piece." + i + ".row"]); var column = parseInt(localStorage["halma.piece." + i + ".column"]); gPieces[i] = new Cell(row, column); } gNumPieces = kNumPieces; gSelectedPieceIndex = parseInt(localStorage["halma.selectedpiece"]); gSelectedPieceHasMoved = localStorage["halma.selectedpiecehasmoved"] == "true"; gMoveCount = parseInt(localStorage["halma.movecount"]); drawBoard(); return true; }

HTML5 in action In the saveGameState() function, we did not worry about the data type: localStorage["halma.game.in.progress"] = gGameInProgress;

HTML5 in action But in the resumeGame() function, we need to treat the value we got from the local storage area as a string and manually construct the proper Boolean value ourselves: gGameInProgress = (localStorage["halma.game.in.progress"] == "true");

HTML5 in action Similarly, the number of moves is stored in gMoveCount as an integer. In the saveGameState() function, we just stored it: gMoveCount = parseInt(localStorage["halma.movecount"]);

HTML5 in action But in the resumeGame() function, we need to coerce the value to an integer, using the parseInt() function built into JavaScript: gMoveCount = parseInt(localStorage["halma.movecount"]);

Beyond Key-Value Pairs: Competing Visions

Beyond Key/Value Pairs: Competing Visions 2007 – Google Gears (based on SQLite) -> Web SQL DatabaseSQLite openDatabase('documents', '1.0', 'Local document storage', 5*1024*1024, function (db) { db.changeVersion('', '1.0', function (t) { t.executeSql('CREATE TABLE docids (id, name)'); }, error); });

Beyond Key/Value Pairs: Competing Visions Web SQL Database The Web SQL Database specification has been implemented by four browsers and platforms.Web SQL Database Safari 4.0+ Chrome 4.0+ Opera Mobile Safari 3.0+ Android 2.0+

Beyond Key/Value Pairs: Competing Visions SQL-92 Oracle SQL Microsoft SQL MySQL PostgreSQL SQLiteSQLite SQL

Beyond Key/Value Pairs: Competing Visions Indexed Database API Formerly known as WebSimpleDB Now colloquially referred to as “indexedDB”

Beyond Key/Value Pairs: Competing Visions IndexedDB object store Shares many concepts with a SQL database: Records (keys or attributes) Fields (values) Datatypes But no query language!

Beyond Key/Value Pairs: Competing Visions Firefox 4: An early walk-through of IndexedDB HTML5 Rocks: IndexedDB example