Offline Application Cache

Offline Application Cache
        Jonathan Stark




              1
What is AppCache?



        2
The Basics



    3
Manifest File

• A simple text document
• Hosted on your web server
• Contains a list of static resources

                      4
demo.manifest
CACHE MANIFEST

index.html

logo.jpg

scripts/demo.js

styles/screen.css



                  5
index.html

<html manifest="demo.manifest">




               6
.htaccess

AddType text/cache-manifest .manifest




                 7
It Works!

• User loads index.html normally
• Listed files download in the background
• User can now go offline

                    8
What About Updates?

• Update your content (HTML, CSS, JS, IMG)
• Update your manifest
• All files re-download next time

                    9
Online Whitelist



       10
demo.manifest
CACHE MANIFEST

index.html

scripts/demo.js

styles/screen.css

NETWORK:

logo.jpg


                  11
Offline Fallbacks



       12
demo.manifest
CACHE MANIFEST

index.html

scripts/demo.js

styles/screen.css

FALLBACK:

logo.jpg offline.jpg


                  13
demo.manifest
CACHE MANIFEST

index.html

scripts/demo.js

styles/screen.css

FALLBACK:

images/ images/offline.jpg


                  14
Dynamic Manifest



       15
manifest.php
<?php
echo "CACHE MANIFESTn";
$dir = new RecursiveDirectoryIterator(".");
foreach(new RecursiveIteratorIterator($dir) as $file) {
    if ($file->IsFile()
    and $file != "./manifest.php"
    and substr($file->getFilename(), 0, 1) != ".") {
        echo $file . "n";
    }
}




                         16
Debugging



    17
access_log
tail -f /var/log/apache2/access_log




                18
JavaScript API
// Convenience array of status values
var cacheStatusValues = [];
cacheStatusValues[0] = 'uncached';
cacheStatusValues[1] = 'idle';
cacheStatusValues[2] = 'checking';
cacheStatusValues[3] = 'downloading';
cacheStatusValues[4] = 'updateready';
cacheStatusValues[5] = 'obsolete';




                              19
JavaScript API
// Listeners for all possible events
var cache = window.applicationCache;
cache.addEventListener('cached', logEvent, false);
cache.addEventListener('checking', logEvent, false);
cache.addEventListener('downloading', logEvent, false);
cache.addEventListener('error', logEvent, false);
cache.addEventListener('noupdate', logEvent, false);
cache.addEventListener('obsolete', logEvent, false);
cache.addEventListener('progress', logEvent, false);
cache.addEventListener('updateready', logEvent, false);




                             20
JavaScript API
// Log every event to the console
function logEvent(e) {
    var online, status, type, message;
    online = (navigator.onLine) ? 'yes' : 'no';
    status = cacheStatusValues[cache.status];
    type = e.type;
    message = 'online: ' + online;
    message+= ', event: ' + type;
    message+= ', status: ' + status;
    if (type == 'error' && navigator.onLine) {
        message+= ' (prolly a syntax error in manifest)';
    }
    console.log(message);
}
                             21
JavaScript API
// Check for manifest changes every 10 seconds
setInterval(function(){cache.update()}, 10000);




                             22
Demo!



  23
More Info

• http://jonathanstark.com/books
• http://jonathanstark.com/contact
• http://jonathanstark.com/e4h

                     24
1 of 24

Recommended

ActionHeroJS Talk by
ActionHeroJS TalkActionHeroJS Talk
ActionHeroJS TalkDavid Peralta
288 views10 slides
ATG pipelines by
ATG pipelinesATG pipelines
ATG pipelinesKate Semizhon
8.4K views23 slides
What happens in laravel 4 bootstraping by
What happens in laravel 4 bootstrapingWhat happens in laravel 4 bootstraping
What happens in laravel 4 bootstrapingJace Ju
2.3K views16 slides
Spout - Building a RESTful web app with Angular.js and BEAR.Sunday by
Spout - Building a RESTful web app with Angular.js and BEAR.SundaySpout - Building a RESTful web app with Angular.js and BEAR.Sunday
Spout - Building a RESTful web app with Angular.js and BEAR.SundayRichard McIntyre
3.4K views46 slides
ATG Advanced Profile Management by
ATG Advanced Profile ManagementATG Advanced Profile Management
ATG Advanced Profile ManagementKate Semizhon
4K views43 slides
API Days Paris - Automatic Testing of (RESTful) API Documentation by
API Days Paris - Automatic Testing of (RESTful) API DocumentationAPI Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationRouven Weßling
438 views26 slides

More Related Content

What's hot

Learning Svelte by
Learning SvelteLearning Svelte
Learning SvelteChristoffer Noring
584 views36 slides
The road to continuous deployment: a case study (DPC16) by
The road to continuous deployment: a case study (DPC16)The road to continuous deployment: a case study (DPC16)
The road to continuous deployment: a case study (DPC16)Michiel Rook
4.2K views46 slides
Learning django step 1 by
Learning django step 1Learning django step 1
Learning django step 1永昇 陳
3.5K views48 slides
Dancing with websocket by
Dancing with websocketDancing with websocket
Dancing with websocketDamien Krotkine
3.8K views28 slides
Lazy Loading Because I'm Lazy by
Lazy Loading Because I'm LazyLazy Loading Because I'm Lazy
Lazy Loading Because I'm LazyJohnathan Leppert
1.6K views11 slides
Javascript Frameworks for Joomla by
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
1.3K views15 slides

What's hot(20)

The road to continuous deployment: a case study (DPC16) by Michiel Rook
The road to continuous deployment: a case study (DPC16)The road to continuous deployment: a case study (DPC16)
The road to continuous deployment: a case study (DPC16)
Michiel Rook4.2K views
Learning django step 1 by 永昇 陳
Learning django step 1Learning django step 1
Learning django step 1
永昇 陳3.5K views
Asynchronous PHP and Real-time Messaging by Steve Rhoades
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
Steve Rhoades19.2K views
"Service Worker: Let Your Web App Feel Like a Native " by FDConf
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
FDConf8.7K views
Better Testing With PHP Unit by sitecrafting
Better Testing With PHP UnitBetter Testing With PHP Unit
Better Testing With PHP Unit
sitecrafting812 views
[Srijan Wednesday Webinar] Rails 5: What's in It for Me? by Srijan Technologies
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
Qualidade de vida: Com Zabbix e API by Luiz Sales
Qualidade de vida: Com Zabbix e APIQualidade de vida: Com Zabbix e API
Qualidade de vida: Com Zabbix e API
Luiz Sales1.2K views
Security Challenges in Node.js by Websecurify
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
Websecurify3.3K views
Laravel Design Patterns by Bobby Bouwmann
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
Bobby Bouwmann24.2K views
Scalable web application architecture by postrational
Scalable web application architectureScalable web application architecture
Scalable web application architecture
postrational32.5K views
XamarinとAWSをつないでみた話 by Takehito Tanabe
XamarinとAWSをつないでみた話XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話
Takehito Tanabe1.7K views

Viewers also liked

Implementing Data Caching and Data Synching Using Oracle MAF by
Implementing Data Caching and Data Synching Using Oracle MAFImplementing Data Caching and Data Synching Using Oracle MAF
Implementing Data Caching and Data Synching Using Oracle MAFSteven Davelaar
2.4K views42 slides
Offnet- Offline Mobile Application by
Offnet- Offline Mobile ApplicationOffnet- Offline Mobile Application
Offnet- Offline Mobile ApplicationSudip Adhikari
388 views16 slides
Offline Strategy for an Online World by
Offline Strategy for an Online WorldOffline Strategy for an Online World
Offline Strategy for an Online WorldSoCal UX Camp
156 views28 slides
Designing For Offline by
Designing For OfflineDesigning For Offline
Designing For OfflineSteven Trevathan
221 views63 slides
Offline First Applications by
Offline First ApplicationsOffline First Applications
Offline First ApplicationsGeekNightHyderabad
589 views23 slides
Offline first: application data and synchronization by
Offline first: application data and synchronizationOffline first: application data and synchronization
Offline first: application data and synchronizationEatDog
2K views45 slides

Viewers also liked(8)

Implementing Data Caching and Data Synching Using Oracle MAF by Steven Davelaar
Implementing Data Caching and Data Synching Using Oracle MAFImplementing Data Caching and Data Synching Using Oracle MAF
Implementing Data Caching and Data Synching Using Oracle MAF
Steven Davelaar2.4K views
Offnet- Offline Mobile Application by Sudip Adhikari
Offnet- Offline Mobile ApplicationOffnet- Offline Mobile Application
Offnet- Offline Mobile Application
Sudip Adhikari388 views
Offline Strategy for an Online World by SoCal UX Camp
Offline Strategy for an Online WorldOffline Strategy for an Online World
Offline Strategy for an Online World
SoCal UX Camp156 views
Offline first: application data and synchronization by EatDog
Offline first: application data and synchronizationOffline first: application data and synchronization
Offline first: application data and synchronization
EatDog2K views
Sync is hard: building offline-first Android apps from the ground up by droidcon Dubai
Sync is hard: building offline-first Android apps from the ground up	Sync is hard: building offline-first Android apps from the ground up
Sync is hard: building offline-first Android apps from the ground up
droidcon Dubai1.9K views
Data Synchronization Patterns in Mobile Application Design by Eric Maxwell
Data Synchronization Patterns in Mobile Application DesignData Synchronization Patterns in Mobile Application Design
Data Synchronization Patterns in Mobile Application Design
Eric Maxwell7.6K views

Similar to Offline Application Cache

Html5 : stockage local & synchronisation by
Html5 : stockage local & synchronisationHtml5 : stockage local & synchronisation
Html5 : stockage local & synchronisationgoldoraf
2.3K views69 slides
HTML5: huh, what is it good for? by
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?Remy Sharp
1.4K views88 slides
Offline strategies for HTML5 web applications - IPC12 by
Offline strategies for HTML5 web applications - IPC12Offline strategies for HTML5 web applications - IPC12
Offline strategies for HTML5 web applications - IPC12Stephan Hochdörfer
836 views81 slides
Running Vue Storefront in production (PWA Magento webshop) by
Running Vue Storefront in production (PWA Magento webshop)Running Vue Storefront in production (PWA Magento webshop)
Running Vue Storefront in production (PWA Magento webshop)Vendic Magento, PWA & Marketing
9.3K views48 slides
Maxim Salnikov - Service Worker: taking the best from the past experience for... by
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Codemotion
193 views78 slides
WCLA12 JavaScript by
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScriptJeffrey Zinn
861 views31 slides

Similar to Offline Application Cache(20)

Html5 : stockage local & synchronisation by goldoraf
Html5 : stockage local & synchronisationHtml5 : stockage local & synchronisation
Html5 : stockage local & synchronisation
goldoraf2.3K views
HTML5: huh, what is it good for? by Remy Sharp
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
Remy Sharp1.4K views
Offline strategies for HTML5 web applications - IPC12 by Stephan Hochdörfer
Offline strategies for HTML5 web applications - IPC12Offline strategies for HTML5 web applications - IPC12
Offline strategies for HTML5 web applications - IPC12
Maxim Salnikov - Service Worker: taking the best from the past experience for... by Codemotion
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Codemotion193 views
Service Worker - Reliability bits by jungkees
Service Worker - Reliability bitsService Worker - Reliability bits
Service Worker - Reliability bits
jungkees821 views
Persistent mobile JavaScript by Yorick Phoenix
Persistent mobile JavaScriptPersistent mobile JavaScript
Persistent mobile JavaScript
Yorick Phoenix830 views
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W... by Robert Nyman
 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W... 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
Robert Nyman7K views
Taking Web Apps Offline by Pedro Morais
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps Offline
Pedro Morais3.6K views
Bonnes pratiques de développement avec Node js by Francois Zaninotto
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
Francois Zaninotto5.7K views
Burn down the silos! Helping dev and ops gel on high availability websites by Lindsay Holmwood
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
Lindsay Holmwood1.6K views
WebAPIs & Apps - Mozilla London by Robert Nyman
WebAPIs & Apps - Mozilla LondonWebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla London
Robert Nyman30.7K views
[Coscup 2012] JavascriptMVC by Alive Kuo
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo1.3K views
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09 by Frédéric Harper
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Frédéric Harper1.3K views
Web APIs & Apps - Mozilla by Robert Nyman
Web APIs & Apps - MozillaWeb APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Robert Nyman17.6K views
Solving anything in VCL by Fastly
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
Fastly13.3K views
Web apps without internet by MSDEVMTL
Web apps without internetWeb apps without internet
Web apps without internet
MSDEVMTL409 views

More from Jonathan Stark

How To Get More Leads And Increase Your Fees - Jonathan Stark by
How To Get More Leads And Increase Your Fees - Jonathan StarkHow To Get More Leads And Increase Your Fees - Jonathan Stark
How To Get More Leads And Increase Your Fees - Jonathan StarkJonathan Stark
229 views29 slides
Make More Money Without Working More Hours by
Make More Money Without Working More HoursMake More Money Without Working More Hours
Make More Money Without Working More HoursJonathan Stark
379 views41 slides
The Hourly Trap by
The Hourly TrapThe Hourly Trap
The Hourly TrapJonathan Stark
278 views12 slides
How To Write Proposals That Close Without Lowering Your Prices by
How To Write Proposals That Close Without Lowering Your PricesHow To Write Proposals That Close Without Lowering Your Prices
How To Write Proposals That Close Without Lowering Your PricesJonathan Stark
172 views7 slides
How To Write Better Proposals by
How To Write Better ProposalsHow To Write Better Proposals
How To Write Better ProposalsJonathan Stark
191 views22 slides
How To Increase Your Income Without Hiring Junior Developers by
How To Increase Your Income Without Hiring Junior DevelopersHow To Increase Your Income Without Hiring Junior Developers
How To Increase Your Income Without Hiring Junior DevelopersJonathan Stark
99 views10 slides

More from Jonathan Stark(20)

How To Get More Leads And Increase Your Fees - Jonathan Stark by Jonathan Stark
How To Get More Leads And Increase Your Fees - Jonathan StarkHow To Get More Leads And Increase Your Fees - Jonathan Stark
How To Get More Leads And Increase Your Fees - Jonathan Stark
Jonathan Stark229 views
Make More Money Without Working More Hours by Jonathan Stark
Make More Money Without Working More HoursMake More Money Without Working More Hours
Make More Money Without Working More Hours
Jonathan Stark379 views
How To Write Proposals That Close Without Lowering Your Prices by Jonathan Stark
How To Write Proposals That Close Without Lowering Your PricesHow To Write Proposals That Close Without Lowering Your Prices
How To Write Proposals That Close Without Lowering Your Prices
Jonathan Stark172 views
How To Write Better Proposals by Jonathan Stark
How To Write Better ProposalsHow To Write Better Proposals
How To Write Better Proposals
Jonathan Stark191 views
How To Increase Your Income Without Hiring Junior Developers by Jonathan Stark
How To Increase Your Income Without Hiring Junior DevelopersHow To Increase Your Income Without Hiring Junior Developers
How To Increase Your Income Without Hiring Junior Developers
Jonathan Stark99 views
Thinking Outside The Little Black Box: Interaction Design in The Post-Mobile Era by Jonathan Stark
Thinking Outside The Little Black Box: Interaction Design in The Post-Mobile EraThinking Outside The Little Black Box: Interaction Design in The Post-Mobile Era
Thinking Outside The Little Black Box: Interaction Design in The Post-Mobile Era
Jonathan Stark404 views
The Revolution Will Not Be Televised: Managing Content and Experience in the ... by Jonathan Stark
The Revolution Will Not Be Televised: Managing Content and Experience in the ...The Revolution Will Not Be Televised: Managing Content and Experience in the ...
The Revolution Will Not Be Televised: Managing Content and Experience in the ...
Jonathan Stark543 views
Rethink Mobile: Mobile Strategy for Product Designers by Jonathan Stark
Rethink Mobile: Mobile Strategy for Product DesignersRethink Mobile: Mobile Strategy for Product Designers
Rethink Mobile: Mobile Strategy for Product Designers
Jonathan Stark1.3K views
The Browser is Dead, Long Live the Web! by Jonathan Stark
The Browser is Dead, Long Live the Web!The Browser is Dead, Long Live the Web!
The Browser is Dead, Long Live the Web!
Jonathan Stark623 views
The Revolution Will Not Be Televised by Jonathan Stark
The Revolution Will Not Be TelevisedThe Revolution Will Not Be Televised
The Revolution Will Not Be Televised
Jonathan Stark5.2K views
Principles of Mobile Interface Design by Jonathan Stark
Principles of Mobile Interface DesignPrinciples of Mobile Interface Design
Principles of Mobile Interface Design
Jonathan Stark15.1K views
Free Coffee, Bad Apples, and the Future of Currency by Jonathan Stark
Free Coffee, Bad Apples, and the Future of CurrencyFree Coffee, Bad Apples, and the Future of Currency
Free Coffee, Bad Apples, and the Future of Currency
Jonathan Stark1.1K views
Enterprise Mobile: The Prosumer Impact On Business by Jonathan Stark
Enterprise Mobile: The Prosumer Impact On BusinessEnterprise Mobile: The Prosumer Impact On Business
Enterprise Mobile: The Prosumer Impact On Business
Jonathan Stark845 views
Mobile Apps and the Enterprise by Jonathan Stark
Mobile Apps and the EnterpriseMobile Apps and the Enterprise
Mobile Apps and the Enterprise
Jonathan Stark3.4K views

Recently uploaded

State of the Union - Rohit Yadav - Apache CloudStack by
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStackShapeBlue
145 views53 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
46 views73 slides
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...Bernd Ruecker
50 views69 slides
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue by
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueShapeBlue
85 views54 slides
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueShapeBlue
46 views13 slides
Scaling Knowledge Graph Architectures with AI by
Scaling Knowledge Graph Architectures with AIScaling Knowledge Graph Architectures with AI
Scaling Knowledge Graph Architectures with AIEnterprise Knowledge
53 views15 slides

Recently uploaded(20)

State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue145 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue by ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
ShapeBlue85 views
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue46 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue96 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu141 views
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T by ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue56 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc77 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue74 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn28 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue63 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays40 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue102 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray1080 views
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue119 views

Offline Application Cache

Editor's Notes

  1. Hi I&amp;#x2019;m Jonathan Stark. I&amp;#x2019;m a software consultant from Providence RI. I do mobile app strategy, design, and development.
  2. There&amp;#x2019;s a feature of HTML5 called the offline application cache (aka AppCache) that allows users to run web apps even when they are not connected to the Internet. It works like this: when a user navigates to your web app, the browser downloads and stores all the files it needs to display the page (HTML, CSS, JavaScript, images, etc.). The next time the user navigates to your web app, the browser will recognize the URL and serve the files out of the local application cache instead of pulling them across the network.
  3. You have to do three things to enable the app cache: - Creating a manifest file - Adding the manifest attribute to HTML open tags - Enabling the text/cache-manifest content type
  4. The main component of the offline application cache is a cache manifest file. A manifest file is just a simple text document that lives on your web server and contains a list of files that a user&amp;#x2019;s device must download and save in order to function.
  5. The paths in the manifest are relative to the location of the manifest file (similar to URLs in CSS files). You can also use absolute URLs if you prefer.
  6. Now that the manifest file is created, you link to it by adding a manifest attribute to the HTML tag inside index.html.
  7. You must serve the manifest file with the text/cache-manifest content type or the browser will not recognize it. If you are using the Apache web server or a compatible web server, you can accomplish this by adding an .htaccess file to your web directory.
  8. Our offline application cache is now in working order. The next time a user browses to http://example.com/index.html, the page and its resources will load normally over the network. In the background, all the files listed in the manifest will be downloaded locally to the user&amp;#x2019;s device. Once the download completes and the user refreshes the page, she&amp;#x2019;ll be accessing the local files only. She can now disconnect from the Internet and continue to access the web app.
  9. So now that the user is accessing our files locally on her device, we have a new problem: how does she get updates when changes are made to the website? When the user does have access to the Internet and navigates to the URL of our web app, her browser checks the manifest file on our site to see if it still matches the local copy. If the remote manifest has changed, the browser downloads all the files listed in it. It downloads these in the background to a temporary cache. The comparison between the local manifest and the remote manifest is a byte-by-byte comparison of the file contents (including comments and blank lines). The file modification timestamp and changes to any of the resources themselves are irrelevant when determining whether or not changes have been made. If something goes wrong during the download (e.g., the user loses her Internet connection), then the partially downloaded cache is automatically discarded and the previous one remains in effect. If the download is successful, the new local files will be used the next time the user launches the app.
  10. Sometimes, you don&amp;#x2019;t want certain files to be cached. Fortunately, app cache offers the option to force the browser to always access certain resources over the network. This means that the browser will not cache those resources locally, and that they will not be available when the user is offline.
  11. To specify a resource as online only, you use the NETWORK: keyword (the trailing : is essential) in the manifest file. Here, I&amp;#x2019;ve whitelisted logo.jpg by moving it into the NETWORK section of the manifest file. When the user is offline, the image will show up as a broken image link. When he is online, it will appear normally.
  12. If you don&amp;#x2019;t want offline users to see the broken image, you can use the FALLBACK keyword to specify a fallback resource.
  13. Now, when the user is offline, he&amp;#x2019;ll see offline.jpg, and when he&amp;#x2019;s online he&amp;#x2019;ll see logo.jpg.
  14. You can also specify a single fallback image for multiple resources by using a partial path. Let&amp;#x2019;s say I add an images directory to my website and put some files in it. I can then tell the browser to fall back to offline.jpg for anything contained in the images directory. Now, when the user is offline, he&amp;#x2019;ll see offline.jpg, and when he&amp;#x2019;s online he&amp;#x2019;ll see the actual online images.
  15. The manifest file is pretty finicky. If you have a single typo, invalid path, etc... it won&amp;#x2019;t work at all. If you have a lot of files in your app, it might make sense to build a manifest file dynamically.
  16. You can use a scripting language like PHP to traverse your directory structure to generate a list of files in your app. Theoretically, you could use this file as your manifest, but in practice this would cause place an unnecessary load on your server. I recommend using the PHP file to help you create a static manifest rather than serving it directly.
  17. It can be tough to debug apps that use the offline application cache because there&amp;#x2019;s very little visibility into what is going on. You find yourself constantly wondering if your files have downloaded, or if you are viewing remote or local resources. Plus, switching your device between online and offline modes is not the snappiest procedure and can really slow down the development cycle.
  18. The best way to ensure that you know what is actually being requested from you web server is to monitor your server logs while interacting with your app. If your manifest is working correctly, you should only see requests for your manifest file and any files listed in the network or fallback sections of the manifest.