SlideShare ist ein Scribd-Unternehmen logo
1 von 70
HTML5 Offline Web Applications Peter Lubbers, Kaazing
Thanks to Our Sponsors! Kaazing (Pizza and Drinks) Enterprise-Ready HTML5 WebSocket Gateway enabling massively scalable, real-time web applications HTML5 and WebSocket Training (Yes, we’re hiring!) Marakana (Organization) Cutting-Edge Open Source Training (San Francisco, New York, Toronto, and on demand) Twilio (Venue) Allows web applications to easily make and receive phone calls and SMS text messages using a simple web service API Apress (Raffle Prizes) Books for professionals by professionals Copyright © 2010 - Kaazing Corporation. All rights reserved.
about:peterlubbers Copyright © 2010 - Kaazing Corporation. All rights reserved.
Agenda About Offline Web Apps  Creating Offline Web Apps Server Configuration Tips, Tricks, and Q&A Copyright © 2010 - Kaazing Corporation. All rights reserved.
Offline Web Applications New HTML5 Specification  Also known as Application Cache (AppCache) WHATWG: http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html#offline W3C: http://dev.w3.org/html5/spec/offline.html#offline Spec is primarily aimed at browser developers to ensure interoperability… Copyright © 2010 - Kaazing Corporation. All rights reserved.
The Spec… WHATWG spec Data for the current section. The format that data lines must take depends on the current section. When the current section is the explicit section, data lines must consist of zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters, a valid URL identifying a resource other than the manifest itself, and then zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters. When the current section is the fallback section, data lines must consist of zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters, a valid URL identifying a resource other than the manifest itself, one or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters, another valid URLidentifying a resource other than the manifest itself, and then zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters. When the current section is the online whitelist section, data lines must consist of zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters, either a single U+002A ASTERISK character (*) or a valid URL identifying a resource other than the manifest itself, and then zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters… Copyright © 2010 - Kaazing Corporation. All rights reserved.
And the SlightlySimplerVersion…  Copyright © 2010 - Kaazing Corporation. All rights reserved. Sweet! I’m offline! How easy was that!
Offline Web Applications Allow you to keep using web apps and sites without a network connection (for example, on an airplane or in rural areas and subways) Copyright © 2010 - Kaazing Corporation. All rights reserved.
Offline without AppCache Copyright © 2010 - Kaazing Corporation. All rights reserved. Noooooooo!
Traditional Caching Cache duration can be controlled through Web Server’s Cache HTTP headers For example, in Apache’s .htaccess file (see example on next slide) Not reliable for offline use Browser caching settings also apply Copyright © 2010 - Kaazing Corporation. All rights reserved.
Web Server Caching Settings .htaccess File <IfModule mod_expires.c>   Header set cache-control: public   ExpiresActive on # your document html    ExpiresByType text/html                  "access" # rss feed   ExpiresByType application/rss+xml       "access plus 1 hour" # favicon (cannot be renamed)   ExpiresByType image/vnd.microsoft.icon  "access plus 1 week"  # media: images, video, audio   ExpiresByType image/png                 "access plus 1 month"   ExpiresByType image/jpg                 "access plus 1 month"   ExpiresByType image/jpeg                "access plus 1 month"   ExpiresByType video/ogg                 "access plus 1 month"   ExpiresByType audio/ogg                 "access plus 1 month"   ExpiresByType video/mp4                 "access plus 1 month" # webfonts   ExpiresByType font/ttf                  "access plus 1 month"   ExpiresByType font/woff                 "access plus 1 month"   ExpiresByType image/svg+xml             "access plus 1 month" # css and javascript   ExpiresByType text/css                  "access plus 1 month"   ExpiresByType application/javascript    "access plus 1 month"   ExpiresByType text/javascript           "access plus 1 month" </IfModule> Source: Paul Irish & DivyaManianhttp://html5boilerplate.com/ Copyright © 2010 - Kaazing Corporation. All rights reserved.
Offline Web Applications Allow you to cache pages that have not been visited Browsers cache data in an Application Cache Once resources are cached, you can access them very quickly (without a network request) HTML5 also allows online and offline detection Using offline mechanism allows you to easily prefetch site resources (speeds up pages, but uses bandwidth) Pages served using TLS (SSL) can also be included to work offline Copyright © 2010 - Kaazing Corporation. All rights reserved.
Source Files: http://bit.ly/9pJ1Zq  or: http://tech.kaazing.com/training/offline/peter-lubbers-html5-offline-web-apps-presentation-code.zip Demo Copyright © 2010 - Kaazing Corporation. All rights reserved.
Browser Support for Offline Web Applications 4.0+ 4.0+ 3.5+ 10.6+ Someday… 	Source: http://caniuse.com/(the best site for checking browser support for HTML5 features) Hi-res browser logos: http://paulirish.com/2010/high-res-browser-icons/ Copyright © 2010 - Kaazing Corporation. All rights reserved.
Offline Emulation HTML5 Gears Project by Brad Neuberg, Google: http://code.google.com/p/html5-gears/ Copyright © 2010 - Kaazing Corporation. All rights reserved.
Developing Offline Web Applications Copyright © 2010 - Kaazing Corporation. All rights reserved.
The Manifest File Manifest File CACHE MANIFEST # manifest version 1.0.1  # Files to cache index.html cache.html html5.css image1.jpg img/foo.gif http://www.example.com/styles.css # Use from network if available NETWORK: network.html # Fallback content FALLBACK: / fallback.html Copyright © 2010 - Kaazing Corporation. All rights reserved.
Using a Manifest File in HTML Reference the manifest file: <name>.manifest – it must match the name of the manifest file Add as attribute to HTML element HTML <!DOCTYPE html> <html manifest="offline.manifest">   <head>     <title>HTML5 Application Cache</title> Copyright © 2010 - Kaazing Corporation. All rights reserved.
Browser Notification Usersmay have to opt in (similar to Geolocation) Configurable and notdefault in all browsers Copyright © 2010 - Kaazing Corporation. All rights reserved.
The Manifest File Manifest file has threesections: CACHE: NETWORK: FALLBACK: Multiple sections (of the same kind) are allowed First linemustbeCACHE MANIFEST Comments start with # (don’t use inline comments) An application cache is created using the manifest’s complete URL (you can have multiple manifest files in a site) Copyright © 2010 - Kaazing Corporation. All rights reserved.
CACHE: Section To cache files in the AppCache, includethem in the CACHE:sectionor list files directlyunderCACHE MANIFEST (default is to cache files) Addone file per line (full name required) Files cancontainpathinformationor even bean absolute URL Applicationcachescan’tincludefragment identifiers(#) or wildcards Case sensitive Files thatreference the manifest file willautomaticallybecached Copyright © 2010 - Kaazing Corporation. All rights reserved.
NETWORK: Section Alsocalled the online whitelist Files listed in thissectionlistedwillnotbeloadedfrom the cache, butretrieved over the network (from the server) if online Youcanspecify“*” Sets the online whitelist wildcard flag to “open” Access to resources on other origins will not be blocked Copyright © 2010 - Kaazing Corporation. All rights reserved.
FALLBACK: Section Provides a way to fall back if resources cannotbefound Specify a fallbacknamespace and a fallback page for that namespace:/ fallback.html You can only list one fallback namespace Copyright © 2010 - Kaazing Corporation. All rights reserved.
Initial Cache Sequence Access the page (with the manifest attribute) Page is loaded and page’s resources are loaded (from the server) Manifest is encountered and parsed, all files flaggedforcaching are loaded in the background Go offline (regularcaching is also in effect, sowatchforfalsepositives) Access a CACHE: resource (loadsfrom cache) Access a NETWORK resource (FALLBACK content is served, files willbeavailableifyou go back online) Copyright © 2010 - Kaazing Corporation. All rights reserved.
Step 1: First Page Load Copyright © 2010 - Kaazing Corporation. All rights reserved.
Step 2: Going Offline Copyright © 2010 - Kaazing Corporation. All rights reserved.
Step 3: Offline Web Page Copyright © 2010 - Kaazing Corporation. All rights reserved.
Step 4: Network Page Copyright © 2010 - Kaazing Corporation. All rights reserved.
Consecutive LoadSequence 1 Go back to online mode Change the cache.html page on the server Reload the cache.html page in the browser The (old) page loadsfrom the application cache (The changes do notappear!) The browser checks to seeif the referencedmanifest file has been updated and does nothingsinceit has not been modified Copyright © 2010 - Kaazing Corporation. All rights reserved.
Consecutive LoadSequence 2 Update the manifest file (make a trivialchange, like a versionnumbercomment update) Reloadthe cache page in the browser The (old) page loadsfrom the applicationcache (This is always the firstactionfrom the browser, so the changesstilldon’tappear!) The browser checks to seeif the referenced manifest has been updated and sinceit has, itdownloads all the files flagged to becached The new files are now in the application cache, reload the page once more to see the latestchanges Copyright © 2010 - Kaazing Corporation. All rights reserved.
Checkingfor Browser Support JavaScript // Simple method if(window.applicationCache) {   // this browser supports offline web apps } //Or just use Modernizr (source: http://www.modernizr.com/) if (Modernizr.applicationcache){   // We have offline web app support! Continue      operation,   // indicating to the user that the app will sync up      once they get back online } else {   // No offline support, show errors if the user goes      offline }  Copyright © 2010 - Kaazing Corporation. All rights reserved.
Checkingfor Online and Offline  Events JavaScript window.addEventListener("online", function(e) {   log("Application is now online"); }, true); window.addEventListener("offline", function(e) {   log("Application is now offline"); }, true); Copyright © 2010 - Kaazing Corporation. All rights reserved.
Using Web Pages Offline Test offline pages using the “Work Offline” feature ifavailable(Not in Chrome andSafari) Disconnectyourcomputer (does notworkforlocalhost) Watch out forfalsepositives (regularbrowser caching) Firefox Opera Copyright © 2010 - Kaazing Corporation. All rights reserved.
Working Offline Copyright © 2010 - Kaazing Corporation. All rights reserved.
ApplicationCache Events The window.applicationCacheobject fires several events related to the state of the cache  window.applicationCache.status is a numerical property indicating the state of the cache 0 UNCACHED 1 IDLE 2 CHECKING 3 DOWNLOADING 4 UPDATEREADY 5 OBSOLETE Copyright © 2010 - Kaazing Corporation. All rights reserved.
EventCallbackAttributes Copyright © 2010 - Kaazing Corporation. All rights reserved.
CheckingApp Cache Status JavaScript window.applicationCache.onchecking = function(e) {     log("Checking for application update"); }  window.applicationCache.onnoupdate = function(e) {     log("No application update found"); } window.applicationCache.onupdateready = function(e) {     log("Application update ready"); window.applicationCache.swapCache(); } window.applicationCache.onobsolete = function(e) {     log("Application obsolete"); } Forces correct behavior in somebrowsers Copyright © 2010 - Kaazing Corporation. All rights reserved.
CheckingApp Cache Status JavaScript window.applicationCache.ondownloading = function(e) {     log("Downloading application update"); } window.applicationCache.oncached = function(e) {     log("Application cached"); } window.applicationCache.onerror = function(e) {     log("Application cache error"); } window.applicationCache.onprogress = function(e) {     log("Application Cache progress"); } Copyright © 2010 - Kaazing Corporation. All rights reserved.
Server Configuration Copyright © 2010 - Kaazing Corporation. All rights reserved.
Serving the Manifest File Manifest files have the MIME type text/cache-manifest Most web servers need to beconfigured to serve the manifest files correctly Servedcorrectlybydefaultby Python's SimpleHTTPServeronUbuntu Linux For Python on Windows/Mac OS X or Apache, update the configuration files with the MIME type Verifyhow the manifest file is servedbyusingnetworkorcurl –I http://offline.example.com/offline.manifest Copyright © 2010 - Kaazing Corporation. All rights reserved. Source: Introducing HTML5, Offline Chapter, Bruce Lawson and Remy Sharp
Apache Configuration mime.types File # Apache mimetype configuration # APACHE_HOME/conf/mime.types text/cache-manifest manifest Or: .htaccess File # Apache mimetype configuration AddType text/cache-manifest .manifest Copyright © 2010 - Kaazing Corporation. All rights reserved.
Apache Configuration .htaccess File # Cache settings for the manifest file <IfModule mod_expires.c>   Header set cache-control: public   ExpiresActive on . . . # Prevent receiving a cached manifest    ExpiresByType text/cache-manifest       "access plus 0 seconds" . . . </IfModule> Source: Introducing HTML5, Offline Chapter, Bruce Lawson and Remy Sharp  Copyright © 2010 - Kaazing Corporation. All rights reserved.
Python Configuration mimetypes.py File # Python SimpleHTTPServer mimetype Configuration # python –m SimpleHTTPServer 9999) '.manifest'    : 'text/cache-manifest', Windows:  PYTHON_HOME/Lib/mimetypes.py, for example: C:ython26ibimetypes.py Mac: PYTHON_HOME/Lib/mimetypes.py, for example: /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/mimetypes.py Important: If you do not have a mimetypes.py file, you can use mimetypes.py from the offline/ mac-config-file examplefolder. If you already have a compiled mimetypes.pyc file in the same directory, ensure that the permissions on this file are changed to read/write. When you start Python with the new file, Python compiles it and generates or overwrites the mimetypes.pyc. Copyright © 2010 - Kaazing Corporation. All rights reserved.
Microsoft IIS Configuration Copyright © 2010 - Kaazing Corporation. All rights reserved.
Copyright © 2010 - Kaazing Corporation. All rights reserved. Offline Web ApplicationsTips and Tricks
Debugging Offline Cache Copyright © 2010 - Kaazing Corporation. All rights reserved. Chrome: ChromeDeveloper Tools > StorageNote: Notavailable in Safari Web Inspectoryet…
AccessingOffline Resources Copyright © 2010 - Kaazing Corporation. All rights reserved.
Accessing the Offline Cache Firefox: about:cache Copyright © 2010 - Kaazing Corporation. All rights reserved.
Accessing the Offline Cache Firefox SQLite Manager Add-on: https://addons.mozilla.org/en-US/firefox/addon/5817/ Copyright © 2010 - Kaazing Corporation. All rights reserved.
Accessing the Offline Cache File System Access Copyright © 2010 - Kaazing Corporation. All rights reserved.
Browser Offline Cache Settings and Clearing the Cache Copyright © 2010 - Kaazing Corporation. All rights reserved.
Offline Cache Settings Copyright © 2010 - Kaazing Corporation. All rights reserved. Firefox: Tools > Options (Preferenceson Mac OS X) > Advanced > Network
Offline Cache Settings Copyright © 2010 - Kaazing Corporation. All rights reserved. Opera: opera:config
Clearing the Cache Copyright © 2010 - Kaazing Corporation. All rights reserved. Chrome: Settings Menu > Tools > ClearBrowsing Data Opera: Tools > Preferences > Storage
Clearing the Cache Copyright © 2010 - Kaazing Corporation. All rights reserved. Firefox: Tools > Clear Recent History Safari: Settings Menu > Reset Safari
Clearing the Cache Note: Close any offline pages beforeyou do this to avoidproblems Copyright © 2010 - Kaazing Corporation. All rights reserved.
Private Browsing Most private browsing modes prevent writing to application cache For example, Safari’s Private Browsingmode, and Chrome’sIncognito Mode Copyright © 2010 - Kaazing Corporation. All rights reserved.
SecurityConsiderations Othersbrowsing the same site (on the same machine in the same browser) canpotentiallyaccessyourcached data (data is cachedbasedon the manifest file URL) Do not store sensitive, personal data in the application cache  Copyright © 2010 - Kaazing Corporation. All rights reserved.
Best Practices Manifest errors are fatal (case sensitive entries) If you are adding and removing (lots of files) files, remember to update the manifest file Use a predeployment script Use a version Comment in the manifest file Host your site on different domain names You can do this on your local machine by hacking the hosts file (see example on the next slide) Windows:INDOWSystem32riverstcosts UNIX: /etc/hosts To see if files are requested, watch the server log Copyright © 2010 - Kaazing Corporation. All rights reserved.
Checking Server Access Copyright © 2010 - Kaazing Corporation. All rights reserved.
hosts File forTesting hosts file # For example 127.0.0.1 localhost127.0.0.1 offline0.example.com 127.0.0.1 offline1.example.com Copyright © 2010 - Kaazing Corporation. All rights reserved.
Disk Quota Don’t assume success and check for errors Example in Chrome: Application Cache Error event: Failed to commit new cache to storage, would exceed quota In the future, browsers will hopefully have graceful quota upgrade mechanisms like Opera’s for LocalStorage Copyright © 2010 - Kaazing Corporation. All rights reserved.
Works WellWith HTML5 Web Storage… JavaScript if (navigator.onLine) {   //Send updates to server } else { window.localStorage.myLocalKey = ‘Some Data';  } } Copyright © 2010 - Kaazing Corporation. All rights reserved.
Cache-As-You-Go If you add the manifest attribute, files will be added to the cache implicitly Subresources and dependencies may not be loaded properly (CSS, JS, etc.) Manifest File CACHE MANIFEST FALLBACK: / /offline.html NETWORK: * Copyright © 2010 - Kaazing Corporation. All rights reserved.
This work is licensed under a Creative Commons Attribution 3.0 License.
Thanks! Kaazing Jobs: http://www.kaazing.com/about/careers.html  E-mail: peter.lubbers@kaazing.com Twitter: @peterlubbers LinkedIN: Peter Lubbers Copyright © 2010 - Kaazing Corporation. All rights reserved.
Resources WHATWG Offline Web Apps spec: http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html#offline W3C Offline Web Apps spec: http://dev.w3.org/html5/spec/offline.html#offline Offline example source files: http://bit.ly/9pJ1Zq Pro HTML5 Programming, Offline chapter, Peter Lubbers, Brian Albers, and Frank Salim Introducing HTML5, Offline chapter, Bruce Lawson and Remy Sharp Copyright © 2010 - Kaazing Corporation. All rights reserved.
HTML5 Training Discount Copyright © 2010 - Kaazing Corporation. All rights reserved. E-mail: training@kaazing.com
Copyright © 2010 Kaazing Corporation, All rights reserved. All materials, including labs and other handouts are property of Kaazing Corporation. Except when expressly permitted by Kaazing Corporation, you may not copy, reproduce, publish, or display any part of this training material, in any form, or by any means. Copyright © 2010 - Kaazing Corporation. All rights reserved.
Using HTML5 Application Cache to Create Offline Web Applications

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 

Kürzlich hochgeladen (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Using HTML5 Application Cache to Create Offline Web Applications

  • 1. HTML5 Offline Web Applications Peter Lubbers, Kaazing
  • 2. Thanks to Our Sponsors! Kaazing (Pizza and Drinks) Enterprise-Ready HTML5 WebSocket Gateway enabling massively scalable, real-time web applications HTML5 and WebSocket Training (Yes, we’re hiring!) Marakana (Organization) Cutting-Edge Open Source Training (San Francisco, New York, Toronto, and on demand) Twilio (Venue) Allows web applications to easily make and receive phone calls and SMS text messages using a simple web service API Apress (Raffle Prizes) Books for professionals by professionals Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 3. about:peterlubbers Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 4. Agenda About Offline Web Apps Creating Offline Web Apps Server Configuration Tips, Tricks, and Q&A Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 5. Offline Web Applications New HTML5 Specification Also known as Application Cache (AppCache) WHATWG: http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html#offline W3C: http://dev.w3.org/html5/spec/offline.html#offline Spec is primarily aimed at browser developers to ensure interoperability… Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 6. The Spec… WHATWG spec Data for the current section. The format that data lines must take depends on the current section. When the current section is the explicit section, data lines must consist of zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters, a valid URL identifying a resource other than the manifest itself, and then zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters. When the current section is the fallback section, data lines must consist of zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters, a valid URL identifying a resource other than the manifest itself, one or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters, another valid URLidentifying a resource other than the manifest itself, and then zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters. When the current section is the online whitelist section, data lines must consist of zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters, either a single U+002A ASTERISK character (*) or a valid URL identifying a resource other than the manifest itself, and then zero or more U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters… Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 7. And the SlightlySimplerVersion… Copyright © 2010 - Kaazing Corporation. All rights reserved. Sweet! I’m offline! How easy was that!
  • 8. Offline Web Applications Allow you to keep using web apps and sites without a network connection (for example, on an airplane or in rural areas and subways) Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 9. Offline without AppCache Copyright © 2010 - Kaazing Corporation. All rights reserved. Noooooooo!
  • 10. Traditional Caching Cache duration can be controlled through Web Server’s Cache HTTP headers For example, in Apache’s .htaccess file (see example on next slide) Not reliable for offline use Browser caching settings also apply Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 11. Web Server Caching Settings .htaccess File <IfModule mod_expires.c> Header set cache-control: public ExpiresActive on # your document html ExpiresByType text/html "access" # rss feed ExpiresByType application/rss+xml "access plus 1 hour" # favicon (cannot be renamed) ExpiresByType image/vnd.microsoft.icon "access plus 1 week" # media: images, video, audio ExpiresByType image/png "access plus 1 month" ExpiresByType image/jpg "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" ExpiresByType video/ogg "access plus 1 month" ExpiresByType audio/ogg "access plus 1 month" ExpiresByType video/mp4 "access plus 1 month" # webfonts ExpiresByType font/ttf "access plus 1 month" ExpiresByType font/woff "access plus 1 month" ExpiresByType image/svg+xml "access plus 1 month" # css and javascript ExpiresByType text/css "access plus 1 month" ExpiresByType application/javascript "access plus 1 month" ExpiresByType text/javascript "access plus 1 month" </IfModule> Source: Paul Irish & DivyaManianhttp://html5boilerplate.com/ Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 12. Offline Web Applications Allow you to cache pages that have not been visited Browsers cache data in an Application Cache Once resources are cached, you can access them very quickly (without a network request) HTML5 also allows online and offline detection Using offline mechanism allows you to easily prefetch site resources (speeds up pages, but uses bandwidth) Pages served using TLS (SSL) can also be included to work offline Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 13. Source Files: http://bit.ly/9pJ1Zq or: http://tech.kaazing.com/training/offline/peter-lubbers-html5-offline-web-apps-presentation-code.zip Demo Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 14. Browser Support for Offline Web Applications 4.0+ 4.0+ 3.5+ 10.6+ Someday… Source: http://caniuse.com/(the best site for checking browser support for HTML5 features) Hi-res browser logos: http://paulirish.com/2010/high-res-browser-icons/ Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 15. Offline Emulation HTML5 Gears Project by Brad Neuberg, Google: http://code.google.com/p/html5-gears/ Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 16. Developing Offline Web Applications Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 17. The Manifest File Manifest File CACHE MANIFEST # manifest version 1.0.1 # Files to cache index.html cache.html html5.css image1.jpg img/foo.gif http://www.example.com/styles.css # Use from network if available NETWORK: network.html # Fallback content FALLBACK: / fallback.html Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 18. Using a Manifest File in HTML Reference the manifest file: <name>.manifest – it must match the name of the manifest file Add as attribute to HTML element HTML <!DOCTYPE html> <html manifest="offline.manifest"> <head> <title>HTML5 Application Cache</title> Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 19. Browser Notification Usersmay have to opt in (similar to Geolocation) Configurable and notdefault in all browsers Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 20. The Manifest File Manifest file has threesections: CACHE: NETWORK: FALLBACK: Multiple sections (of the same kind) are allowed First linemustbeCACHE MANIFEST Comments start with # (don’t use inline comments) An application cache is created using the manifest’s complete URL (you can have multiple manifest files in a site) Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 21. CACHE: Section To cache files in the AppCache, includethem in the CACHE:sectionor list files directlyunderCACHE MANIFEST (default is to cache files) Addone file per line (full name required) Files cancontainpathinformationor even bean absolute URL Applicationcachescan’tincludefragment identifiers(#) or wildcards Case sensitive Files thatreference the manifest file willautomaticallybecached Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 22. NETWORK: Section Alsocalled the online whitelist Files listed in thissectionlistedwillnotbeloadedfrom the cache, butretrieved over the network (from the server) if online Youcanspecify“*” Sets the online whitelist wildcard flag to “open” Access to resources on other origins will not be blocked Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 23. FALLBACK: Section Provides a way to fall back if resources cannotbefound Specify a fallbacknamespace and a fallback page for that namespace:/ fallback.html You can only list one fallback namespace Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 24. Initial Cache Sequence Access the page (with the manifest attribute) Page is loaded and page’s resources are loaded (from the server) Manifest is encountered and parsed, all files flaggedforcaching are loaded in the background Go offline (regularcaching is also in effect, sowatchforfalsepositives) Access a CACHE: resource (loadsfrom cache) Access a NETWORK resource (FALLBACK content is served, files willbeavailableifyou go back online) Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 25. Step 1: First Page Load Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 26. Step 2: Going Offline Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 27. Step 3: Offline Web Page Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 28. Step 4: Network Page Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 29. Consecutive LoadSequence 1 Go back to online mode Change the cache.html page on the server Reload the cache.html page in the browser The (old) page loadsfrom the application cache (The changes do notappear!) The browser checks to seeif the referencedmanifest file has been updated and does nothingsinceit has not been modified Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 30. Consecutive LoadSequence 2 Update the manifest file (make a trivialchange, like a versionnumbercomment update) Reloadthe cache page in the browser The (old) page loadsfrom the applicationcache (This is always the firstactionfrom the browser, so the changesstilldon’tappear!) The browser checks to seeif the referenced manifest has been updated and sinceit has, itdownloads all the files flagged to becached The new files are now in the application cache, reload the page once more to see the latestchanges Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 31. Checkingfor Browser Support JavaScript // Simple method if(window.applicationCache) { // this browser supports offline web apps } //Or just use Modernizr (source: http://www.modernizr.com/) if (Modernizr.applicationcache){ // We have offline web app support! Continue operation, // indicating to the user that the app will sync up once they get back online } else { // No offline support, show errors if the user goes offline } Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 32. Checkingfor Online and Offline Events JavaScript window.addEventListener("online", function(e) { log("Application is now online"); }, true); window.addEventListener("offline", function(e) { log("Application is now offline"); }, true); Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 33. Using Web Pages Offline Test offline pages using the “Work Offline” feature ifavailable(Not in Chrome andSafari) Disconnectyourcomputer (does notworkforlocalhost) Watch out forfalsepositives (regularbrowser caching) Firefox Opera Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 34. Working Offline Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 35. ApplicationCache Events The window.applicationCacheobject fires several events related to the state of the cache window.applicationCache.status is a numerical property indicating the state of the cache 0 UNCACHED 1 IDLE 2 CHECKING 3 DOWNLOADING 4 UPDATEREADY 5 OBSOLETE Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 36. EventCallbackAttributes Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 37. CheckingApp Cache Status JavaScript window.applicationCache.onchecking = function(e) { log("Checking for application update"); } window.applicationCache.onnoupdate = function(e) { log("No application update found"); } window.applicationCache.onupdateready = function(e) { log("Application update ready"); window.applicationCache.swapCache(); } window.applicationCache.onobsolete = function(e) { log("Application obsolete"); } Forces correct behavior in somebrowsers Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 38. CheckingApp Cache Status JavaScript window.applicationCache.ondownloading = function(e) { log("Downloading application update"); } window.applicationCache.oncached = function(e) { log("Application cached"); } window.applicationCache.onerror = function(e) { log("Application cache error"); } window.applicationCache.onprogress = function(e) { log("Application Cache progress"); } Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 39. Server Configuration Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 40. Serving the Manifest File Manifest files have the MIME type text/cache-manifest Most web servers need to beconfigured to serve the manifest files correctly Servedcorrectlybydefaultby Python's SimpleHTTPServeronUbuntu Linux For Python on Windows/Mac OS X or Apache, update the configuration files with the MIME type Verifyhow the manifest file is servedbyusingnetworkorcurl –I http://offline.example.com/offline.manifest Copyright © 2010 - Kaazing Corporation. All rights reserved. Source: Introducing HTML5, Offline Chapter, Bruce Lawson and Remy Sharp
  • 41. Apache Configuration mime.types File # Apache mimetype configuration # APACHE_HOME/conf/mime.types text/cache-manifest manifest Or: .htaccess File # Apache mimetype configuration AddType text/cache-manifest .manifest Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 42. Apache Configuration .htaccess File # Cache settings for the manifest file <IfModule mod_expires.c> Header set cache-control: public ExpiresActive on . . . # Prevent receiving a cached manifest ExpiresByType text/cache-manifest "access plus 0 seconds" . . . </IfModule> Source: Introducing HTML5, Offline Chapter, Bruce Lawson and Remy Sharp Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 43. Python Configuration mimetypes.py File # Python SimpleHTTPServer mimetype Configuration # python –m SimpleHTTPServer 9999) '.manifest' : 'text/cache-manifest', Windows: PYTHON_HOME/Lib/mimetypes.py, for example: C:ython26ibimetypes.py Mac: PYTHON_HOME/Lib/mimetypes.py, for example: /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/mimetypes.py Important: If you do not have a mimetypes.py file, you can use mimetypes.py from the offline/ mac-config-file examplefolder. If you already have a compiled mimetypes.pyc file in the same directory, ensure that the permissions on this file are changed to read/write. When you start Python with the new file, Python compiles it and generates or overwrites the mimetypes.pyc. Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 44. Microsoft IIS Configuration Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 45. Copyright © 2010 - Kaazing Corporation. All rights reserved. Offline Web ApplicationsTips and Tricks
  • 46. Debugging Offline Cache Copyright © 2010 - Kaazing Corporation. All rights reserved. Chrome: ChromeDeveloper Tools > StorageNote: Notavailable in Safari Web Inspectoryet…
  • 47. AccessingOffline Resources Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 48. Accessing the Offline Cache Firefox: about:cache Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 49. Accessing the Offline Cache Firefox SQLite Manager Add-on: https://addons.mozilla.org/en-US/firefox/addon/5817/ Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 50. Accessing the Offline Cache File System Access Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 51. Browser Offline Cache Settings and Clearing the Cache Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 52. Offline Cache Settings Copyright © 2010 - Kaazing Corporation. All rights reserved. Firefox: Tools > Options (Preferenceson Mac OS X) > Advanced > Network
  • 53. Offline Cache Settings Copyright © 2010 - Kaazing Corporation. All rights reserved. Opera: opera:config
  • 54. Clearing the Cache Copyright © 2010 - Kaazing Corporation. All rights reserved. Chrome: Settings Menu > Tools > ClearBrowsing Data Opera: Tools > Preferences > Storage
  • 55. Clearing the Cache Copyright © 2010 - Kaazing Corporation. All rights reserved. Firefox: Tools > Clear Recent History Safari: Settings Menu > Reset Safari
  • 56. Clearing the Cache Note: Close any offline pages beforeyou do this to avoidproblems Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 57. Private Browsing Most private browsing modes prevent writing to application cache For example, Safari’s Private Browsingmode, and Chrome’sIncognito Mode Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 58. SecurityConsiderations Othersbrowsing the same site (on the same machine in the same browser) canpotentiallyaccessyourcached data (data is cachedbasedon the manifest file URL) Do not store sensitive, personal data in the application cache Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 59. Best Practices Manifest errors are fatal (case sensitive entries) If you are adding and removing (lots of files) files, remember to update the manifest file Use a predeployment script Use a version Comment in the manifest file Host your site on different domain names You can do this on your local machine by hacking the hosts file (see example on the next slide) Windows:INDOWSystem32riverstcosts UNIX: /etc/hosts To see if files are requested, watch the server log Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 60. Checking Server Access Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 61. hosts File forTesting hosts file # For example 127.0.0.1 localhost127.0.0.1 offline0.example.com 127.0.0.1 offline1.example.com Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 62. Disk Quota Don’t assume success and check for errors Example in Chrome: Application Cache Error event: Failed to commit new cache to storage, would exceed quota In the future, browsers will hopefully have graceful quota upgrade mechanisms like Opera’s for LocalStorage Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 63. Works WellWith HTML5 Web Storage… JavaScript if (navigator.onLine) { //Send updates to server } else { window.localStorage.myLocalKey = ‘Some Data'; } } Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 64. Cache-As-You-Go If you add the manifest attribute, files will be added to the cache implicitly Subresources and dependencies may not be loaded properly (CSS, JS, etc.) Manifest File CACHE MANIFEST FALLBACK: / /offline.html NETWORK: * Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 65. This work is licensed under a Creative Commons Attribution 3.0 License.
  • 66. Thanks! Kaazing Jobs: http://www.kaazing.com/about/careers.html E-mail: peter.lubbers@kaazing.com Twitter: @peterlubbers LinkedIN: Peter Lubbers Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 67. Resources WHATWG Offline Web Apps spec: http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html#offline W3C Offline Web Apps spec: http://dev.w3.org/html5/spec/offline.html#offline Offline example source files: http://bit.ly/9pJ1Zq Pro HTML5 Programming, Offline chapter, Peter Lubbers, Brian Albers, and Frank Salim Introducing HTML5, Offline chapter, Bruce Lawson and Remy Sharp Copyright © 2010 - Kaazing Corporation. All rights reserved.
  • 68. HTML5 Training Discount Copyright © 2010 - Kaazing Corporation. All rights reserved. E-mail: training@kaazing.com
  • 69. Copyright © 2010 Kaazing Corporation, All rights reserved. All materials, including labs and other handouts are property of Kaazing Corporation. Except when expressly permitted by Kaazing Corporation, you may not copy, reproduce, publish, or display any part of this training material, in any form, or by any means. Copyright © 2010 - Kaazing Corporation. All rights reserved.