HTML5 JavaScript Storage for Structured Data Andy Gup, Esri

Slides:



Advertisements
Similar presentations
Bruce Scharlau, University of Aberdeen, 2012 Data storage options for mobiles Mobile Computing.
Advertisements

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 Applications with ASP.NET Web Forms Stephen Walther Superexpert.com
Building Mobile Apps in the Cloud – Comparing Approaches.
PGN5: KAING, RISHER AND SCHULTE PERSISTENT COOKIES WITH BROWSER FINGERPRINTING.
HTML 5 The next generation of web programming. WHERE IT ALL BEGAN.
Working With Data on Titanium Local Data Remote Data Titanium Data Options:
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Presented by…. Group 2 1. Programming language 2Introduction.
Chapter 25 Utilizing Web Storage.
Martin Kruliš by Martin Kruliš (v1.0)1.
Tips for working with disconnected web mapping apps Andy Gup, Javier Abadia.
JavaScript Form Validation
User Interface Design using jQuery Mobile CIS 136 Building Mobile Apps 1.
JavaScript & jQuery the missing manual Chapter 11
Databases.  Multi-table queries  Join ▪ An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them. 
MongoDB An introduction. What is MongoDB? The name Mongo is derived from Humongous To say that MongoDB can handle a humongous amount of data Document.
Google Maps API. Static Maps send an HTTP GET request receive an image (PNG, GIF, JPEG) no javascript needed encode params in URL example:
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications James Walden Northern Kentucky University
Building Native Mapping Apps with PhoneGap: Advanced Techniques
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
PACS - 09/19/15 1 favicon A ‘Favorite icon’ is a file containing one or more small icons associated with a particular website or web page. Web browsers.
WEB WORKERS 1 Amitesh Madhur (Exceptional Performance, Bangalore)
HTML5. HTML5’s overall theme The browser as a rich application platform rich, cross-device user interfaces offline operation capability hardware access.
Feature Windows Phone IE10 iOS Safari Android Chrome Blackberry WebKit Web Storage Yes (7)YesYes (2)Yes (6) Geolocation Yes.
NOSQL DATABASES Please remember to read the NOSQL Distilled book and the Seven Databases book.
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.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Strategies for Building Mobile Apps Using ArcGIS API for JavaScript Andy Gup, Lloyd Heberlie.
Android Storage. There are several options for storage of data with Android We can put data into a preferences file. We can put data into a ‘normal’ file.
ArcGIS Runtime SDK for iOS: Debugging Offline Feature Editing Garima Bradley &)&) &)&)
CHAPTER 15 HTML 5 VIDEO AND AUDIO Intro to HTML5 1.
Esri UC 2014 | Technical Workshop | Creating Geoprocessing Services Kevin Hibma.
Trunica Inc. 500 East Kennedy Blvd #300 Tampa, FL Cross Platform Mobile Apps With Cordova and Visual Studio 2015 © Copyright 2015.
Don’t Disconnect Me! The challenges of building offline-enabled web apps Matthias Oßwald,
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Building Native Apps with ArcGIS API for JavaScript Using PhoneGap and jQuery Andy Gup, Lloyd Heberlie.
CS2550 Dr. Brian Durney. SOURCES  JavaScript: The Definitive Guide, by David Flanagan  Dive into HTML5, by Mark Pilgrim
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Dynamo: Amazon’s Highly Available Key-value Store DAAS – Database as a service.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
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.
Thực hiện: D3 GVLT: BROWERS. Browser Compatibility I Check the compatibility II Tools III.
ScriptOnce™ & Best Practices. Agenda 2 Automation that works ScriptOnce –Minimal maintenance –Easy to add devices Robustness –Reliable Scripts - Minimize.
Reading ROOT files in (almost) any browser.  Use XMLHttpRequest JavaScript class to perform the HTTP HEAD and GET requests  This class is highly browser.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
JQUERY AND AJAX
Paragon The Platform and Message Broker. Paragon: The Platform Stack -Window Management -Messaging -App Lifecycle Management -App Store -Workspaces -Storage.
JQuery form submission CIS 136 Building Mobile Apps 1.
Using HTML5 to Build Offline Applications Woody Pewitt Icenium
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
4.3. Code animations by using JavaScript Access data access by using JavaScript. Creating Animations, Working with Graphics, and Accessing Data.
Phonegap Bridge – Storage CIS 136 Building Mobile Apps 1.
Web Storage and Cookies Cookies, Local and Session Storage SoftUni Team Technical Trainers Software University
QML and JavaScript for Native App Development Michael Tims Jen Trieu.
Development of Internet Applications HTML5 Ing. Jan Janoušek 7.
Unit 9.1 Learning Objectives Data Access in Code
CSE 154 Lecture 11: AJAx.
Data Virtualization Tutorial… CORS and CIS
Enhancing Web Map Performance in ArcGIS Online
CIS 136 Building Mobile Apps
CIS 136 Building Mobile Apps
HTML5 APIs for Data Handling and Processing
Who Am I? appMobi's lead HTML5 game developer / evangelist
CSE 154 Lecture 11: AJAx.
Building offline access in Metro style apps and websites using HTML5
CSE 154 Lecture 22: AJAX.
CIS 136 Building Mobile Apps
CIS 136 Building Mobile Apps
Presentation transcript:

HTML5 JavaScript Storage for Structured Data Andy Gup, Esri

IndexedDB and the mobile web

Why attend this session? Have storage needs > 5MBs Want to store data types other than Strings Don’t want to manually serialize/deserialize Looking into offline JavaScript

Agenda Intro to IndexedDB coding patterns Fitting IndexedDB into overall application Performance Wet your appetite! Can’t cover it all

Who am I? Andy Gup, Esri Sr. Developer – JS and native Android

Structured data? JSON Objects (not serialized) Complex Objects (difficult serialize/deserialize) Binary data (e.g. images, files) Arrays

Offline JavaScript Demo

IndexedDB browser support? Source: Caniuse.com

IndexedDB browser support? Source: Caniuse.com

How does IndexedDB work? Key-Value pairs Search Indexes NoSQL Cursors Asynchronous via callbacks Notifications via DOM events

Key/Value pairs? Key String, Number, Date, Array Value (partial list) String Object Array Blob ArrayBuffer Uint8Array File

Will IndexedDB work offline? YES! Can also be used with Application Cache.

How to use? Six basic steps 1.Include shim (if necessary) 2.Set vendor prefixes 3.Validate functionality 4.Open (or upgrade) 5.Add, update, retrieve or delete data 6.Capture events via callbacks

How to use? IndexedDBShim.js Required for Safari 7 on iOS and Mac Safari 7 only comes with Web SQL

How to use? Set Prefixes window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; var transaction = window.IDBTransaction || window.webkitIDBTransaction;

How to use? Validate functionality this.isSupported = function(){ if(!window.indexedDB && !window.openDatabase){ return false; } return true; };

How to use? Validate functionality this.isSupported = function(callback){ if(!window.indexedDB && !window.openDatabase){ return callback(false); } else{ testFunctionality(function(success,result){ return callback(success,result); }); } };

How to use? Validate functionality function testFunctionality(callback){... var objectStore = transaction.objectStore("table1"); var request = objectStore.put(myBlob,”test1key”); request.onsuccess = function(event) { callback(true,event.target.result); }; request.onerror = function(error) { callback(false,error); }; }

How to use? Open database var db = null; var request = indexedDB.open(“customerDB”, /*version*/ 2); request.onsuccess = function(event){ db = event.target.result; callback(true); } request.onerror = function(error){ callback(false,error); } STEP 1 STEP 2

How to use? Transactions Handles ALL reading and writing var transaction = db.transaction(["customerDB"], "readwrite"); Provides events Three modes “readonly” “readwrite” “versionchange”

How to use? Transaction events var transaction = db.transaction(["customerDB"], "readwrite"); transaction.onerror = function(error){... } // // Careful! This always returns // transaction.oncomplete = function(event){... }

How to use? Transaction requests var transaction = db.transaction(["customerDB"], "readwrite"); var objectStore = transaction.objectStore(“customerDB”); var request = objectStore.put({test:1},”myKey”); // Did transaction request work or not? request.onerror = function(error){... }request.onsuccess = function(event){... } STEP 1 STEP 2 STEP 3 STEP 4

How to use? Write data add(anyValue, /*optional*/ key) Write only unique values Duplicate entries fail with error put(anyValue, /*optional*/ key) Overwrites existing entries with same key

How to use? Write data request = objectStore.put({test:1},”myKey”); request.onsuccess = function(event){ callback(true,event.target.result); } request.onerror = function(error){ callback(false,error); }

How to use? Get data request = objectStore.get(“aUniqueKey”); request.onsuccess = function(event){ callback(true,event.target.result); } request.onerror = function(error){ callback(false,error); }

Read/Write performance Know thy data! Not all data types perform equally Pre- and post-processing is expensive

DEMO Use case: Write-once, read-many Test: data-type read performance Data: 319KB JPEG

Chrome – MacBook 319KB JPEG

Safari – MacBook (Shim) 319KB JPEG Whoa!!

Safari iPad 3 (Shim) 319KB JPEG

Safari 7 iPhone 5 (Shim) 319KB JPEG Whoa!!

Safari 8 iPhone 5S (no shim!) 319KB JPEG

Firefox Desktop – MacBook 319KB JPEG

Android – Nexus 4 319KB JPEG

Pre- and Post-processing What final data type does your app need? Pre-process Work done before ‘writing’ data to DB Post-process Work done after ‘getting’ data from DB

Pre- and Post-processing Potentially huge performance differences Examples -FileReader -Canvas -Bitwise conversion -Blob to objectURL

Pre-processing 1. Retrieve data from or server 2. Convert data (if needed) 3. Write to database Write Convert

Post-processing 1. Retrieve data from database 2. Convert data (if needed) 3. Display/use data Get Display

Pre- and Post-processing XMLHTTPRequest response types

Pre- and Post-processing (Example) var uInt8Array = new Uint8Array(arrBuffer); var blob = new Blob( [uInt8Array], {type:"image/jpeg"}); var image = document.createElement("img"); var urlCreate = window.URL || window.webkitURL; var url = urlCreate.createObjectURL(blob); image.src = url; image.height = 30; image.onload = function(e){ callback(image); URL.revokeObjectURL(this.src); } OUTPUT INPUT

DEMO Test different ways to process images: FileReader API Canvas API Bitwise manipulation Use three different image types: PNG, GIF and PNG

Convert ArrayBuffer to Image* GIF PNG JPG * Chrome 35

Convert ArrayBuffer to Image* * Chrome 35

Convert ArrayBuffer to Image PNG JPG

DEMO Offline mapping Storing large amounts of images

Database size – how big?? General suggestion (smartphones/tablet): - Less than 100 MB Why? Depends on: -Remaining free memory -How much memory used by browser -How many tabs are already open -If other applications already running

Can I use too much memory? YES! The device OS will shutdown the browser Greater potential for data corruption/loss If shutdown occurs during a ‘write’ operation

Summary - IndexedDB Designed to work with complex data. High performance/Asynchronous Compatible with many offline workflows Browser support continues to improve

References

Questions? Andy Gup, Esri Sr. Developer – JS and native Android