HTML5 Offline Data. INF5750/9750 - Lecture 6 (Part II)



Similar documents
How To Write A Web Server In Javascript

HTML 5 stockage local

Web application Architecture

General principles and architecture of Adlib and Adlib API. Petra Otten Manager Customer Support

Web Browser. Fetches/displays documents from web servers. Mosaic 1993

Getting Started with Android Programming (5 days) with Android 4.3 Jelly Bean

Client-Side Storage in Web Applications

The Risks of Client-Side Data Storage From cookie to database

HTML5 and Device APIs for Automotive: Is it time to power Infotainment and Car Portal Applications with Web Technologies?

Zero Downtime Deployments with Database Migrations. Bob Feldbauer

Safari Client-Side Storage and Offline Applications Programming Guide

Installation and Administration Guide

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

Abusing HTML5. DEF CON 19 Ming Chow Lecturer, Department of Computer Science TuCs University Medford, MA

Offline-First Apps with PouchDB and IBM Cloudant

Upgrade to Microsoft Web Applications

Programming in HTML5 with JavaScript and CSS3

Lecture 9 Chrome Extensions

Mobile Web Applications using HTML5. L. Cotfas 14 Dec. 2011

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

Android Development Exercises Version Hands On Exercises for. Android Development. v

Automate Your BI Administration to Save Millions with Command Manager and System Manager

Cyber Security Challenge Australia 2014

slides at goo.gl/kifue

User-password application scripting guide

THE LINK OFFLINE DATA ARCHITECTURE

NoSQL web apps. w/ MongoDB, Node.js, AngularJS. Dr. Gerd Jungbluth, NoSQL UG Cologne,

XML Processing and Web Services. Chapter 17

DATA SYNCHRONIZATION ON MOBILE DEVICES

Developing Offline Web Application

Smartphone Enterprise Application Integration

IMRG Peermap API Documentation V 5.0

Development Techniques for Native/Hybrid Tizen Apps. Presented by Kirill Kruchinkin

Grupo Lanka s Pivotal Development tools are integrated by the follow individual products:

Operational Decision Manager Worklight Integration

MarkLogic Server. Database Replication Guide. MarkLogic 8 February, Copyright 2015 MarkLogic Corporation. All rights reserved.

Client-Side Web Programming (Part 2) Robert M. Dondero, Ph.D. Princeton University

Design Document. Offline Charging Server (Offline CS ) Version i -

Tizen Web Runtime Update. Ming Jin Samsung Electronics

HTML5 / NATIVE / HYBRID

ADOBE AIR. Working with Data in AIR. David Tucker

ios SDK possibilities & limitations

NoSQL replacement for SQLite (for Beatstream) Antti-Jussi Kovalainen Seminar OHJ-1860: NoSQL databases

Integrating Remedyforce

Google Developer Group Perugia DevFest Central Rome

The evolution of database technology (II) Huibert Aalbers Senior Certified Executive IT Architect

ITG Software Engineering

How To Build A Web App

User s manual. Magento extension. BCP - Better Configurable Products

Assignment 3 Version 2.0 Reactive NoSQL Due April 13

WI005 - Offline data sync con SQLite in Universal Windows Platform

Designing for the Mobile Web Lesson 3: HTML5 Web Apps

Smartphone Application Development using HTML5-based Cross- Platform Framework

QML and JavaScript for Native App Development

Web Same-Origin-Policy Exploration Lab

Responsive, resilient, elastic and message driven system

HTML5. Eoin Keary CTO BCC Risk Advisory.

Copyright 2014, Oracle and/or its affiliates. All rights reserved.

SpatialWare. Version for Microsoft SQL Server 2008 INSTALLATION GUIDE

Web Design Technology

What about MongoDB? can req.body.input 0; var date = new Date(); do {curdate = new Date();} while(curdate-date<10000)

It is highly recommended that you are familiar with HTML and JavaScript before attempting this tutorial.

SalesLogix. SalesLogix v6 Architecture, Customization and Integration

Migrate Topaz databases from One Server to Another

Client SuiteScript Developer s Guide

Enterprise Mobile Web Development. Robert Altland Principal Consultant, Mobility Neudesic, LLC

Web Cloud Architecture

Configuring SQL Server Lock (Block) Monitoring With Sentry-go Quick & Plus! monitors

Facebook Twitter YouTube Google Plus Website

Web Development using PHP (WD_PHP) Duration 1.5 months

Modern Web Development From Angle Brackets to Web Sockets

Pay with Amazon Integration Guide

Sharding with postgres_fdw

Programming IoT Gateways With macchina.io

Getting Started with Telerik Data Access. Contents

iservdb The database closest to you IDEAS Institute

HTML5 Top 10 Threats - Stealth Attacks and Silent Exploits

Category: Business Process and Integration Solution for Small Business and the Enterprise

Workflow Templates Library

Cloud Elements ecommerce Hub Provisioning Guide API Version 2.0 BETA

QNX SDK for Apps and Media 1.0. HTML5 Developer's Guide

FileMaker Server 14. Custom Web Publishing Guide

Getting Started with Overdrive on a Kindle Fire

Visualizing an OrientDB Graph Database with KeyLines

Chapter 2: Interactive Web Applications

getsharedpreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter.

PTC Integrity Eclipse and IBM Rational Development Platform Guide

Introduction to Tizen SDK Alpha. Taiho Choi Samsung Electronics

September 2009 Cloud Storage for Cloud Computing

Up and Running with LabVIEW Web Services

Electronic Ticket and Check-in System for Indico Conferences

Transcription:

HTML5 Offline Data INF5750/9750 - Lecture 6 (Part II)

What is offline? The Web and Online are considered to be synonymous, then what is HTML offline? HTML content distributed over CDs/DVDs, always offline Apps can be online-offline and sync when online Certain information is kept offline and not synced. This is generally non-critical information like user searches etc. Two specific solutions to doing offline data Application Cache (Logic offline) Offline Storage (Data offline)

Application Cache The core to HTML5 Application Cache (AppCache) is cache manifest file, i.e. a text file that lists the resources the browser should cache for offline access <html manifest="example.appcache">... </html> OR <html manifest="http://www.example.com/example.mf"> mimetype should be text/cache-manifest and follows same-origin policy Structure of a manifest file: CACHE MANIFEST # 2010-06-18:v2 CACHE: /favicon.ico index.html stylesheet.css images/logo.png scripts/main.js # Resources that require the user to be online. NETWORK: login.php /myapi http://api.twitter.com

Updating the cache window.applicationcache object is your programmatic access AppCache var appcache = window.applicationcache; switch (appcache.status) { case appcache.uncached: // UNCACHED == 0 return 'UNCACHED'; break; case appcache.idle: // IDLE == 1 return 'IDLE'; break;. appcache.update(); if (appcache.status == window.applicationcache.updateready) { appcache.swapcache(); // The fetch was successful, swap in the new cache. } You can also use listeners to check the status of cache // Fired after the first cache of the manifest. appcache.addeventlistener('cached', handlecacheevent, false); // An update was found. The browser is fetching resources. appcache.addeventlistener('downloading', handlecacheevent, false); // Fired for each resource listed in the manifest as it is being fetched. appcache.addeventlistener('progress', handlecacheevent, false); // Fired when the manifest resources have been newly redownloaded. appcache.addeventlistener('updateready', handlecacheevent, false);

Offline storage options APIs for offline storage work in same origin policy : Web Storage API (localstorage) WebSQL IndexedDB File Storage

Web Storage Simplistic structure of key-value pairs like JSON // Saving a full JSON object using Web storage localstorage[ student"] = JSON.stringify(StudentObject) // Retrieving the saved StudentObject var student= JSON.parse(localStorage[ student"]). src: html5rocks.com

Web SQL (deprecated) In-browser implementation of SQL Most implementations in browsers are using SQLite 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); }); Overhead for converting to SQL statements from JavaScript Not object oriented in its application Few browsers supported and has been deprecated

IndexedDB A balance between Web Storage and WebSQL Transactions available and search is indexed for speed IndexedDB databases store key-value pairs The IndexedDB API is mostly asynchronous IndexedDB uses DOM events to notify you when results are available IndexedDB is object-oriented IndexedDB does not use Structured Query Language (SQL)

Using IndexedDB The basic pattern that IndexedDB encourages is the following: Open a database and start a transaction. Create an object store. Make a request for db operation, like adding or retrieving data. Wait for the operation to complete by listening to DOM event. Do something with results (which is available on request object). // Start by checking if browser supports the feature if (!window.indexeddb) { window.alert("your browser doesn't support IndexedDB"); } // Let us open our database and check for error or success in opening the DB var request = window.indexeddb.open("mytestdatabase", 3); request.onerror = function(event) { // Do something with request.errorcode! }; request.onsuccess = function(event) { // Do something with request.result! }; // Create an objectstore for this database var objectstore = db.createobjectstore("name", { keypath: "mykey" });

Storing and Retrieving data // Data var studentlocation = [ { name: "Jane Fonda", age: 22, longitude: "23.352", latitude: 42.954"}, { name : "Julian Assange", age: 25, longitude: "24.662", latitude: 42.991" } ]; const dbname = loc"; var request = indexeddb.open(dbname, 2); //name = loc and version = 2 request.onupgradeneeded = function(event) { var db = event.target.result; // Create an objectstore to hold students. //Start with "name" as our key path because our model ensures it to be unique. var objectstore = db.createobjectstore( students", { keypath: name" }); // Create an index to search students by longitude and latitude. objectstore.createindex("longitude", "longitude", { unique: false }); objectstore.createindex("latitude", " latitude ", { unique: false }); }; // Store values in the newly created objectstore. for (var i in customerdata) { objectstore.add(customerdata[i]); } //Adding a transaction and deleting data var transaction = db.transaction([ loc"], "readwrite ).objectstore ( students").delete( Jane Fonda"); request.onsuccess = function(event) { alert( Deleted successfully ); }; //Adding a transaction and retrieving data db.transaction( loc").objectstore( students").get( Julian Assange").onsuccess = function(event) { alert( Longitude = " + event.target.result.longitude); };

Using a cursor Using get() requires that you know which key to retrieve // Get all students in store var objectstore = db.transaction( loc").objectstore( students"); //Adding a transaction and retrieving data objectstore.opencursor().onsuccess = function(event) { var cursor = event.target.result; if (cursor) { alert( Student: " + cursor.key + " is " + cursor.value.name); cursor.continue(); } else { alert("no more entries!"); } } Searching directly on an index var index = objectstore.index( latitude"); index.get("23.352").onsuccess = function(event) { alert( At latitude 23.352, student is " + event.target.result.name); }; When the browser shuts down, any pending IndexedDB transactions are (silently) aborted -- they will not complete, and they will not trigger the error handler

Resources A summary of Offline Storage http://www.html5rocks.com/en/features/storage IndexedDB at MDN https://developer.mozilla.org/en-us/docs/indexeddb/using_indexeddb Migrating from WebSQL to IndexedDB http://www.html5rocks.com/en/tutorials/webdatabase/websqlindexeddb/