Taking Web Applications Offline

31
Taking Web Applications Offline Matt Casto http://google.com/profiles/ mattcasto

description

One of the main advantages of web applications is their ease of deployment. The same can't be said about desktop applications. However, desktop applications work without a network connection. While this used to be a deal breaker for web applications, recent developments in HTML 5 and browser plugins such as Flash and Silverlight allow developers to create web applications that work both online and offline. In this session, Matt will demonstrate how to create offline web applications in HTML 5, Silverlight and Air. Also, other factors for offline applications, such as client-side data storage, will be examined in detail.

Transcript of Taking Web Applications Offline

Page 1: Taking Web Applications Offline

Taking WebApplications Offline

Matt Castohttp://google.com/profiles/mattcasto

Page 2: Taking Web Applications Offline

Offline Web - Oxymoron

“Why would you want to use the web offline?”

- Some dude in an airplane

Page 3: Taking Web Applications Offline

Making The Case

Example: Survey application that needs to work both online and in areas with little or no internet connectivity.

Page 4: Taking Web Applications Offline

Bandwidth Isn’t Ubiquitous

Page 5: Taking Web Applications Offline

Traditional Caching

Page 6: Taking Web Applications Offline

HTML5 App Cache

• http://www.w3.org/TR/html5/offline.html

• http://www.whatwg.org/specs/web-apps/current-work/ multipage/offline.html

Page 7: Taking Web Applications Offline

CACHE MANIFEST# version 0.0.8

CACHE:index.htmlsite.cssjquery-1.4.1.jsemoticon_smile.png

NETWORK:noncached.html

FALLBACK:/ offline.html

Page 8: Taking Web Applications Offline

CACHE MANIFEST# version 0.0.8

CACHE:index.htmlsite.cssjquery-1.4.1.jsemoticon_smile.png

NETWORK:noncached.html

FALLBACK:/ offline.html

Page 9: Taking Web Applications Offline

CACHE MANIFEST# version 0.0.8

CACHE:index.htmlsite.cssjquery-1.4.1.jsemoticon_smile.png

NETWORK:noncached.html

FALLBACK:/ offline.html

Page 10: Taking Web Applications Offline

CACHE MANIFEST# version 0.0.8

CACHE:index.htmlsite.cssjquery-1.4.1.jsemoticon_smile.png

NETWORK:noncached.html

FALLBACK:/ offline.html

Page 11: Taking Web Applications Offline

<!DOCTYPE HTML><html manifest="manifest.cache"> <head> <title>Hello AppCache</title> <link href="site.css" rel="stylesheet“ type="text/css" /> <script src="jquery-1.4.1.js" type="text/javascript"></script> </head> <body> <h1>Hello AppCache!</h1> </body></html>

Page 12: Taking Web Applications Offline

MIME type

text/cache-manifest

Page 13: Taking Web Applications Offline

Cached Page – First Load

1. Page with manifest attribute is requested.2. The page is loaded (including referenced assets)3. The browser loads the manifest file and parses

it.4. The browser loads indicated files in the

background.5. At this point all of these resources will now be

loaded from the browser’s cache!

Page 14: Taking Web Applications Offline

Cached Page – Additional Load

1. Page that the browser has cached is requested.

2. The browser loads the file from its cache.3. The browser attempts to load the manifest

file from the server.4. If changes have been made to the manifest

file, all resources are re-cached.5. If the current page was re-cached, changes

won’t show up unless the user refreshes.

Page 15: Taking Web Applications Offline

Browser Support – App Cache

Source – http://caniuse.com

Page 16: Taking Web Applications Offline

DEMO – Simple Cached Site

Page 17: Taking Web Applications Offline

if (navigator.onLine)alert(“We’re online!”);

window.addEventListener(“online”, function(e) { alert(“online”); }, true);

window.addEventListener(“offline”, function(e) { alert(“offline”); }, true);

Page 18: Taking Web Applications Offline

Browser Support - onLine

Source – http://caniuse.com

Page 19: Taking Web Applications Offline

DEMO – OnLine/OffLine App

Page 20: Taking Web Applications Offline

HTML5 Data Storage

Key/Value data storage by the browserat either the Session or Persistent level.

http://dev.w3.org/html5/webstorage/

Page 21: Taking Web Applications Offline

sessionStorage.setItem(“key”, “value”);sessionStorage.getItem(“key”,

“value”);sessionStorage.removeItem(“key”);sessionStorage.clear();

localStorage.setItem(“key”, “value”);localStorage.getItem(“key”, “value”);localStorage.removeItem(“key”);localStorage.clear();

Page 22: Taking Web Applications Offline

Browser Support – Storage

Source – http://caniuse.com

Page 23: Taking Web Applications Offline

DEMO – Local Storage App

Page 25: Taking Web Applications Offline

Browser Plug-Ins

Page 26: Taking Web Applications Offline
Page 27: Taking Web Applications Offline
Page 28: Taking Web Applications Offline

DEMO – Developer Survey

Page 29: Taking Web Applications Offline

Security Concerns

Page 30: Taking Web Applications Offline

Other Concerns

• Error Handling• Logging• Printing• Authentication• Authorization

Page 31: Taking Web Applications Offline

Resources

HTML5 spec – http://www.w3.org/TR/html5

Examples• http://diveintohtml5.org• http://www.html5rocks.com/tutorials

Silverlight – http://www.silvelight.netAdobe AIR – http://www.adobe.com/AIR

me• http://google.com/profiles/mattcasto • http://speakerrate.com/talks/5289-taking-web-applications-offline • http://

www.slideshare.net/mattcasto/taking-web-applications-offline-6531560