Taking WebApplications Offline<br />Matt Casto<br />http://google.com/profiles/mattcasto<br />
Offline Web - Oxymoron<br />“Why would you want to use the web offline?”<br /><ul><li> Some dude in an airplane</li></li><...
Bandwidth Isn’t Ubiquitous<br />
Traditional Caching<br />
HTML5 App Cache<br /><ul><li>http://www.w3.org/TR/html5/offline.html
http://www.whatwg.org/specs/web-apps/current-work/ multipage/offline.html </li></li></ul><li>CACHE MANIFEST<br /># version...
CACHE MANIFEST<br /># version 0.0.8<br />CACHE:<br />index.html<br />site.css<br />jquery-1.4.1.js<br />emoticon_smile.png...
CACHE MANIFEST<br /># version 0.0.8<br />CACHE:<br />index.html<br />site.css<br />jquery-1.4.1.js<br />emoticon_smile.png...
CACHE MANIFEST<br /># version 0.0.8<br />CACHE:<br />index.html<br />site.css<br />jquery-1.4.1.js<br />emoticon_smile.png...
<!DOCTYPE HTML><br /><htmlmanifest="manifest.cache"><br />    <head><br />        <title>Hello AppCache</title><br />     ...
MIME type<br />text/cache-manifest<br />
Cached Page – First Load<br />Page with manifest attribute is requested.<br />The page is loaded (including referenced ass...
Cached Page – Additional Load<br />Page that the browser has cached is requested.<br />The browser loads the file from its...
Browser Support – App Cache<br />Source – http://caniuse.com<br />
DEMO – Simple Cached Site<br />
if (navigator.onLine)<br />alert(“We’re online!”);<br />window.addEventListener(“online”, function(e) { alert(“online”); }...
Browser Support - onLine<br />Source – http://caniuse.com<br />
DEMO – OnLine/OffLine App<br />
HTML5 Data Storage<br />Key/Value data storage by the browser<br />at either the Session or Persistent level.<br />http://...
sessionStorage.setItem(“key”, “value”);<br />sessionStorage.getItem(“key”, “value”);<br />sessionStorage.removeItem(“key”)...
Browser Support – Storage<br />Source – http://caniuse.com<br />
DEMO – Local Storage App<br />
Offline Database<br />Source – http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(HTML_5)<br />
Browser Plug-Ins<br />
DEMO – Developer Survey<br />
Security Concerns<br />
Other Concerns<br /><ul><li>Error Handling
Logging
Printing
Upcoming SlideShare
Loading in …5
×

Taking Web Applications Offline

8,523 views

Published on

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.

Published in: Technology, Design
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,523
On SlideShare
0
From Embeds
0
Number of Embeds
1,255
Actions
Shares
0
Downloads
97
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • There is no such thing as “offline web apps” – this is an oxymoron. However, web applications can take advantage of browser capabilities and work without a network connection.This quote goes alone with a short story about my flight earlier this week, where my upcoming presentation at CodeMash was the topic. When I told my fellow traveler what my session’s title was, this was what he said.
  • As a case study, I describe my current contract with the State of Ohio. They have a long standing ASP.NET web application and they needed a new portion of that site to be available offline for auditors that visit homes that get state government assistance with their heating bills. These auditors need to record information about the electricity usage of appliances and suggest replacements that would use less energy (thus, saving money).
  • Internet not available or the website is down.
  • You (the developer) can control the cache duration through your web server’s cache settings, but its not reliable for offline use. Also, you have no control over the user’s browser settings.
  • The HTML5 specification is more for browser developers, not web application developers, but it can give you an idea of whats going on.
  • The cache manifest file contains instructions for the browser to determine how to cache your pages.
  • The CACHE section includes pages you want the browser to cache, even if the user hasn’t browsed to them. Note that pages that reference the manifest file will automatically be cached, but its nice to be explicit and include them. Also note that resources, such as CSS files, javascript files and images, must be referenced in order to be loaded into the cache.
  • The NETWORK section is where to include pages that should only be available when a network connection is available.
  • The fallback section allows you to reference a web page to display when certain pages are requested and there is no network. You can list specific pages, or use a wild card * to define a fall back page for all non-cached pages. The fallback page is implicitly cached by the browser.
  • The cache manifest file is referenced as an attribute on the HTML tag in your pages that “kick off” caching.
  • You must associate the “text/cache-manifest” MIME type with the file extension you’re using for the cache manifest file. Typically the file will be named “cache.manifest” but I’m using “manifest.cache” since the “.manifest” file extension is already associated with a different MIME type in IIS 7.Note that you can’t use the ASP.NET Development Server (Cassini) to test this since you can’t set up MIME types.
  • Step 3 is where things can go wrong. If there is a problem with ANY part of the manifest file, the whole caching process fails.
  • Note that step 3 will fail if the user is currently working offline or has no network connection.Also, its very important to note that pages that have been changed won’t be re-loaded unless the cache manifest file has also changed.
  • Note that each browser has a different maximum storage amount for cached pages, and there aren’t currrently any APIs or mechanisms in place for increasing that quota – its up to the user!
  • Show a simple site and demonstrate caching. Show debug information in Chrome Developr Tools and javascript events that haven’t been covered in slides.
  • That’s great, but what about doing real work offline … instead of just displaying cached pages?The HTML5 spec calls for a flag that indicates whether the user is online, and events that are raised when the network status changes.
  • Pretty much the same coverage as AppCache, although webkit based browsers don’t have a “work offline” feature, which means you have to have not network connectivity to change the onLine flag – tough to test when developing against localhost. Also, webkit based browsers won’t update the onLine flag until the page is refreshed (VERIFY!!)
  • As you can see, pretty much all major browsers support local and session key/value storage.
  • Web SQL Database was part of the HTML5 specification for a SQLite database implementation in the browser, but several browsers have stated that they won’t support it and its currently only supported on WebKit browsers. The Indexed Database API looks more promising as far as future browser support, but it isn’t a viable solution today. Also, there have been lots of concerns about missing features in Indexed Database such as encryption.
  • Flash has been the solution for developers who want a local database for a while now with several 3rd party database implementations. Silverlight is a good alternative for .NET developers.
  • If you want to work offline with a browser plug-in, you don’t really want to cache a page with the plug-in as content – this doesn’t have any advantage over regular caching. Adobe Flash projects can be created to target the AIR runtime which runs out of the browser, has a native SQLite implementation, and is supported in all modern operating systems.
  • Microsoft’s Silverlight Out of Browser (OOB) capabilities are a nice alternative to Adobe AIR for .NET developers and is supported on modern Windows and Mac operating systems. There is no support for *nix operating systems, although there’s a 3rd party implementation called Moonlight developd by Novell’s Mono team. There is currently no local database suppport, but there are open source implementations.
  • This demonstration is an ASP.NET MVC web application that allows the user to enter survey results and submit them. There is a form for HTML5 storage and caching, there’s a form for Silverlight in and out of browser, and a page with an AIR installer. All 3 implementations of the survey form post to the save ASP.NET MVC controller action.
  • Just like anything sent to the browser in an HTML page, anything stored in local storage, no matter what browser or plug-in is used, is available for people to access. Its also possible that users on machines that are shared by multiple users could access each other’s data. Its important to keep this in mind when developing with these features.
  • There are lots of other things you should take into consideration if you need to build an offline capable web application; including error handling, logging, printing, authentication / authorization…If these are a big deal for you, maybe you should develop a thick client instead!
  • Taking Web Applications Offline

    1. 1. Taking WebApplications Offline<br />Matt Casto<br />http://google.com/profiles/mattcasto<br />
    2. 2. Offline Web - Oxymoron<br />“Why would you want to use the web offline?”<br /><ul><li> Some dude in an airplane</li></li></ul><li>Making The Case<br />Example: Survey application that needs to work both online and in areas with little or no internet connectivity.<br />
    3. 3. Bandwidth Isn’t Ubiquitous<br />
    4. 4. Traditional Caching<br />
    5. 5. HTML5 App Cache<br /><ul><li>http://www.w3.org/TR/html5/offline.html
    6. 6. http://www.whatwg.org/specs/web-apps/current-work/ multipage/offline.html </li></li></ul><li>CACHE MANIFEST<br /># version 0.0.8<br />CACHE:<br />index.html<br />site.css<br />jquery-1.4.1.js<br />emoticon_smile.png<br />NETWORK:<br />noncached.html<br />FALLBACK:<br />/ offline.html<br />
    7. 7. CACHE MANIFEST<br /># version 0.0.8<br />CACHE:<br />index.html<br />site.css<br />jquery-1.4.1.js<br />emoticon_smile.png<br />NETWORK:<br />noncached.html<br />FALLBACK:<br />/ offline.html<br />
    8. 8. CACHE MANIFEST<br /># version 0.0.8<br />CACHE:<br />index.html<br />site.css<br />jquery-1.4.1.js<br />emoticon_smile.png<br />NETWORK:<br />noncached.html<br />FALLBACK:<br />/ offline.html<br />
    9. 9. CACHE MANIFEST<br /># version 0.0.8<br />CACHE:<br />index.html<br />site.css<br />jquery-1.4.1.js<br />emoticon_smile.png<br />NETWORK:<br />noncached.html<br />FALLBACK:<br />/ offline.html<br />
    10. 10. <!DOCTYPE HTML><br /><htmlmanifest="manifest.cache"><br /> <head><br /> <title>Hello AppCache</title><br /> <link href="site.css" rel="stylesheet“<br /> type="text/css" /><br /> <script src="jquery-1.4.1.js"<br /> type="text/javascript"></script><br /> </head><br /> <body><br /> <h1>Hello AppCache!</h1><br /> </body><br /></html><br />
    11. 11. MIME type<br />text/cache-manifest<br />
    12. 12. Cached Page – First Load<br />Page with manifest attribute is requested.<br />The page is loaded (including referenced assets)<br />The browser loads the manifest file and parses it.<br />The browser loads indicated files in the background.<br />At this point all of these resources will now be loaded from the browser’s cache!<br />
    13. 13. Cached Page – Additional Load<br />Page that the browser has cached is requested.<br />The browser loads the file from its cache.<br />The browser attempts to load the manifest file from the server.<br />If changes have been made to the manifest file, all resources are re-cached.<br />If the current page was re-cached, changes won’t show up unless the user refreshes.<br />
    14. 14. Browser Support – App Cache<br />Source – http://caniuse.com<br />
    15. 15. DEMO – Simple Cached Site<br />
    16. 16. if (navigator.onLine)<br />alert(“We’re online!”);<br />window.addEventListener(“online”, function(e) { alert(“online”); }, true);<br />window.addEventListener(“offline”, function(e) { alert(“offline”); }, true);<br />
    17. 17. Browser Support - onLine<br />Source – http://caniuse.com<br />
    18. 18. DEMO – OnLine/OffLine App<br />
    19. 19. HTML5 Data Storage<br />Key/Value data storage by the browser<br />at either the Session or Persistent level.<br />http://dev.w3.org/html5/webstorage/<br />
    20. 20. sessionStorage.setItem(“key”, “value”);<br />sessionStorage.getItem(“key”, “value”);<br />sessionStorage.removeItem(“key”);<br />sessionStorage.clear();<br />localStorage.setItem(“key”, “value”);<br />localStorage.getItem(“key”, “value”);<br />localStorage.removeItem(“key”);<br />localStorage.clear();<br />
    21. 21. Browser Support – Storage<br />Source – http://caniuse.com<br />
    22. 22. DEMO – Local Storage App<br />
    23. 23. Offline Database<br />Source – http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(HTML_5)<br />
    24. 24. Browser Plug-Ins<br />
    25. 25.
    26. 26.
    27. 27. DEMO – Developer Survey<br />
    28. 28. Security Concerns<br />
    29. 29. Other Concerns<br /><ul><li>Error Handling
    30. 30. Logging
    31. 31. Printing
    32. 32. Authentication
    33. 33. Authorization</li></li></ul><li>Resources<br />HTML5 spec – http://www.w3.org/TR/html5<br />Examples<br /><ul><li>http://diveintohtml5.org
    34. 34. http://www.html5rocks.com/tutorials</li></ul>Silverlight – http://www.silvelight.net<br />Adobe AIR – http://www.adobe.com/AIR<br />me<br /><ul><li>http://google.com/profiles/mattcasto
    35. 35. http://speakerrate.com/talks/
    36. 36. http://www.slideshare.net/mattcasto/</li>

    ×