SlideShare a Scribd company logo
Always ON!
…or not?
Carsten Sandtner (@casarock)
mediaman GmbH
about:me
Carsten Sandtner
@casarock
Technical Director
mediaman GmbH
Always on! Or not?
Always on! Or not?
The Beginning
NilsPeters-https://flic.kr/p/9k2Wdp
Browser Cache
Cookies
BrettJordan-https://flic.kr/p/7ZRSzA
Ancient Times
ThomasConté-https://flic.kr/p/9dzzpc
Application
Cache
„HTML5 provides an application caching mechanism
that lets web-based applications run offline.
Developers can use the Application Cache (AppCache)
interface to specify resources that the browser should
cache and make available to offline users.“
-MDN
https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache
The
TRUTH
• FILES ALWAYS COME FROM THE APPLICATIONCACHE, EVEN IF YOU’RE
ONLINE
• THE APPLICATIONCACHE ONLY UPDATES IF THE CONTENT OF THE
MANIFEST ITSELF HAS CHANGED
• THE APPLICATIONCACHE IS AN ADDITIONAL CACHE, NOT AT ALTERNATIVE
ONE
• NEVER EVER EVER FAR-FUTURE CACHE THE MANIFEST
• NON-CACHED RESOURCES WILL NOT LOAD ON A CACHED PAGE
• WE DON’T KNOW HOW WE GOT TO THE FALLBACK PAGE
• …
– Jake Archibald
http://alistapart.com/article/application-cache-is-a-douchebag
„Application Cache is a Douchebag“
2016
W3C decides to remove application cache
from standard
AlexanderBoden-https://flic.kr/p/pMrQ1N
Things are getting better
Web
Storages
Web Storages
• key/value store
• localStorage
• sessionStorage
localStorage
localStorage.myCar = 'Volkswagen Beetle';
localStorage['myCar'] = 'Volkswagen Beetle';
localStorage.setItem('myCar', 'Volkswagen Beetle');
let myCar = localStorage.getItem('myCar');
window.addEventListener('storage', function(e) { ... }
localStorage.removeItem('myCar');
localStorage.clear()
let complexType = {type: 'Beetle', manufacturer: 'Volkswagen'}
localStorage.setItem('myCar', JSON.stringify(complexType));
sessionStorage
sessionStorage.myCar = 'Volkswagen Beetle';
sessionStorage['myCar'] = 'Volkswagen Beetle';
sessionStorage.setItem('myCar', 'Volkswagen Beetle');
let myCar = sessionStorage.getItem('myCar');
window.addEventListener('storage', function(e) { ... }
sessionStorage.removeItem('myCar');
sessionStorage.clear()
let complexType = {type: 'Beetle', manufacturer: 'Volkswagen'}
sessionStorage.setItem('myCar', JSON.stringify(complexType));
WebStorages
• easy to use!
• good browser support!
• But:
• http/https define different stores!
• asynchronous
• Quota?
IndexedDB
–Wikipedia
https://en.wikipedia.org/wiki/Indexed_Database_API
„The Indexed Database API, or IndexedDB (formerly
WebSimpleDB), is a W3C recommended web
browser standard interface for a transactional local
database of JSON objects collections with indices.“
IndexedDB: Open/Create
var indexedDB = window.indexedDB || window.mozIndexedDB ||
window.webkitIndexedDB || window.msIndexedDB;
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("FancyNamedStore", {keyPath: "id"});
var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
};
open.onsuccess = function() {};
open.onfailure = function() {};
IndexedDB: Write/Read
open.onsuccess = function() {
var db = open.result;
var tx = db.transaction("FancyNamedStore", "readwrite");
var store = tx.objectStore("FancyNamedStore");
var index = store.index("NameIndex");
store.put({id: 12345, name: {first: "John", last: "Bar"}, age: 42});
store.put({id: 67890, name: {first: "Bob", last: "Foo"}, age: 35});
var getJohn = store.get(12345);
var getBob = index.get(["Foo", "Bob"]);
getJohn.onsuccess = function() {
console.log(getJohn.result.name.first); // => "John"
};
getBob.onsuccess = function() {
console.log(getBob.result.name.first); // => "Bob"
};
tx.oncomplete = function() {
db.close();
};
}
Always on! Or not?
localForage* FTW!
* or any other library… like Store.js 

(https://github.com/marcuswestin/store.js/)
„localForage is a JavaScript library that improves the
offline experience of your web app by using an
asynchronous data store with a simple, localStorage-
like API. It allows developers to store many types of
data instead of just strings.“
–https://localforage.github.io
„localForage includes a localStorage-backed fallback
store for browsers with no IndexedDB or WebSQL
support. Asynchronous storage is available in the
current versions of all major browsers: Chrome,
Firefox, IE, and Safari (including Safari Mobile).“
–https://localforage.github.io
„localForage offers a callback API as well as support
for the ES6 Promises API, so you can use
whichever you prefer.“
–https://localforage.github.io
LocalForage
localforage.config({
driver : localforage.WEBSQL, // localforage.INDEXEDDB
// localforage.WEBSQL
// localforage.LOCALSTORAGE
name : 'carFinder',
version : 1.0,
size : 4980736, // Size of database, in bytes. WebSQL-only for now.
storeName : 'mycars', // Should be alphanumeric, with underscores.
description : 'Store all infos about my cars'
});
localforage.setItem('car', 'beetle').then(function () {
return localforage.getItem('car');
}).then(function (value) {
// Success, we've got a value
}).catch(function (err) {
// something went wrong
});
Modern Times
Image©byAppleComputerInc.
Service
Workers
— https://github.com/w3c/ServiceWorker
„Service workers are a new browser feature that
provide event-driven scripts that run independently of
web pages. Unlike other workers, service workers
can be shut down at the end of events, note the lack
of retained references from documents, and they
have access to domain-wide events such as
network fetches.“
— https://github.com/w3c/ServiceWorker
„Service workers also have scriptable caches. Along
with the ability to respond to network requests from
certain web pages via script, this provides a way for
applications to “go offline”.“
Introduction
☁🖥 Internet
1
2
☁🖥 Internet
📜Service Worker
1 2
3
☁
🖥
Internet
📜Service Worker
📁Cache
1
2
3
3
☁
🖥
Internet
📜Service Worker
📁Cache
5
3
2
4
1
☁
🖥
Internet
📜Service Worker
📁Cache
❌
1
2
3
4
Code
Register Service Worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw-test/sw.js', {scope: '/sw-test/'})
.then(function(reg) {
// registration worked
console.log('Registration succeeded. Scope is ' + reg.scope);
}).catch(function(error) {
// registration failed
console.log('Registration failed with ' + error);
});
}
Service Worker Overview
self.addEventListener('install', function(event) {
console.log("installed");
});
self.addEventListener('activate', function(event) {
console.log("activated");
});
self.addEventListener('fetch', function(event) {
console.log("fetch");
event.respondWith(new Response("My response!!"));
});
Install
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open('v1').then(function(cache) {
return cache.addAll([
'/images/myImage.png',
'/index.html'
]);
})
);
});
Fetch
this.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
Fetch & Update Cache
this.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(resp) {
return resp || fetch(event.request).then(function(response) {
caches.open('v1').then(function(cache) {
cache.put(event.request, response.clone());
});
return response;
});
}).catch(function() {
return caches.match('/sw-test/gallery/myLittleVader.jpg');
})
);
});
Clean Up Cache
this.addEventListener('activate', function(event) {
var cacheWhitelist = ['v2'];
event.waitUntil(
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
if (cacheWhitelist.indexOf(key) === -1) {
return caches.delete(key);
}
}));
})
);
});
Update Cache
var CACHE_NAME = 'static-v9';
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(CACHE_NAME_STATIC).then(function(cache) {
return cache.addAll(['...']);
})
)
});
self.addEventListener('activate', function(event) {
var cacheWhitelist = [CACHE_NAME_STATIC];
event.waitUntil(
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
if (cacheWhitelist.indexOf(key) === -1) {
return caches.delete(key);
}
}));
})
);
});
We have the tools!
https://jakearchibald.github.io/isserviceworkerready/
GonzaloBaeza-https://flic.kr/p/dCPzuE
Now & The Future
Progressive
Web Apps
–Ada Rose Edwards
https://www.smashingmagazine.com/2016/09/the-building-blocks-of-progressive-web-apps/
„An ideal web app is a web page that has the best
aspects of both the web and native apps. It should
be fast and quick to interact with, fit the device’s
viewport, remain usable offline and be able to have
an icon on the home screen.“
OMG! PWA? WTF?
• Progressive
• Responsive
• Connectivity independent
• App-like
• Safe
• Discoverable
• Installable
• Linkable
PWA Architecture
„Thorsten“-https://flic.kr/p/y3ib6k
App Shell
Service Workers
www.audio-luci-store.it-https://flic.kr/p/hQannE
Installability
Push Notification
• Allow SW to wake up
• Works in Background, only SW is woken up
• Needs permission from user!
–W3C
https://w3c.github.io/push-api/
„The Push API enables sending of a push message
to a webapp via a push service.“
And Webpages?
–Slightly modified by me…
„An ideal web page is a web page that has the best
aspects of both the web and native apps. It should
be fast and quick to interact with, fit the device’s
viewport and remain usable offline and be able to
have an icon on the home screen.“
Cache Data from APIs
• localStorage
• sessionStorage
• IndexedDB
Are you online?
var online = navigator.onLine;
if (!online) {
// Fallback -> Get Data from Storage!
}
else {
// Use network....
}
That’s easy!
Always on! Or not?
Wait?
• Slow network? (Edge, GPRS etc.)
• mobile networks are not reliable…
• „Lie“-Fi
Use Service Workers
• Provide offline fallback
• Cache static files
• Controll the network ;)
Demo
https://github.com/casarock/service-worker-demo
GPRS
GPRS + SW
Considerations
• Don't abuse offline caches.
• How to deal with sensitive information?
• Are my assets permanently stored?
• Think about your use case!
Always on
is a lie.
Carsten Sandtner
@casarock
sandtner@mediaman.de
https://github.com/casarock
¯_(ツ)_/¯

More Related Content

PPTX
What is HTML 5?
PDF
Offline first, the painless way
PDF
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
PDF
How to make Ajax work for you
PDF
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
PDF
APIs for modern web apps
PPT
High Performance Ajax Applications
PDF
Using Web Standards to create Interactive Data Visualizations for the Web
What is HTML 5?
Offline first, the painless way
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
How to make Ajax work for you
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
APIs for modern web apps
High Performance Ajax Applications
Using Web Standards to create Interactive Data Visualizations for the Web

What's hot (20)

PDF
[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager
PPTX
High Performance JavaScript (CapitolJS 2011)
PPT
Going Offline with Gears And GWT
PDF
Everything is Awesome - Cutting the Corners off the Web
PDF
Easing offline web application development with GWT
PPTX
Ajax ppt - 32 slides
PDF
Dan Webb Presentation
PPT
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
PDF
Instant and offline apps with Service Worker
PDF
Keypoints html5
PDF
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
PPTX
Real World Lessons in Progressive Web Application & Service Worker Caching
PDF
The Complementarity of React and Web Components
PDF
Chrome enchanted 2015
PDF
Ajax Security
KEY
An Introduction to webOS
PDF
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
PDF
Choosing a Javascript Framework
PPT
WordPress and Ajax
PDF
Introduction to Node.js
[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager
High Performance JavaScript (CapitolJS 2011)
Going Offline with Gears And GWT
Everything is Awesome - Cutting the Corners off the Web
Easing offline web application development with GWT
Ajax ppt - 32 slides
Dan Webb Presentation
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Instant and offline apps with Service Worker
Keypoints html5
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
Real World Lessons in Progressive Web Application & Service Worker Caching
The Complementarity of React and Web Components
Chrome enchanted 2015
Ajax Security
An Introduction to webOS
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
Choosing a Javascript Framework
WordPress and Ajax
Introduction to Node.js
Ad

Similar to Always on! Or not? (20)

PDF
Always on! ... or not?
PDF
Angular Offline Progressive Web Apps With NodeJS
PPTX
PWA basics for developers
PDF
Offline progressive web apps with NodeJS and React
PDF
Stop the internet, i want to go offline
PDF
Service workers are your best friends
PDF
A year with progressive web apps! #DevConMU
PDF
Velocity EU 2014 — Offline-first web apps
PPTX
Progressive web applications
PDF
Service worker API
PDF
"Progressive Web Apps" by Riza Fahmi (Hacktiv8)
PDF
Progressive Web Apps. What, why and how
PDF
JavaScript Service Worker Design Patterns for Better User Experience
PDF
Connection lost... F%CK!
PDF
Service workers
PPTX
Progressive Web Applications - The Next Gen Web Technologies
PDF
Progressive Web Apps
PPTX
GDG Ibadan #pwa
PPTX
Raising ux bar with offline first design
Always on! ... or not?
Angular Offline Progressive Web Apps With NodeJS
PWA basics for developers
Offline progressive web apps with NodeJS and React
Stop the internet, i want to go offline
Service workers are your best friends
A year with progressive web apps! #DevConMU
Velocity EU 2014 — Offline-first web apps
Progressive web applications
Service worker API
"Progressive Web Apps" by Riza Fahmi (Hacktiv8)
Progressive Web Apps. What, why and how
JavaScript Service Worker Design Patterns for Better User Experience
Connection lost... F%CK!
Service workers
Progressive Web Applications - The Next Gen Web Technologies
Progressive Web Apps
GDG Ibadan #pwa
Raising ux bar with offline first design
Ad

More from Carsten Sandtner (15)

PDF
State of Web APIs 2017
PDF
Headless in the CMS
PDF
Night Watch with QA
PDF
WebVR - MobileTechCon Berlin 2016
PDF
Evolution der Web Entwicklung
PDF
WebVR - JAX 2016
PDF
HTML5 Games for Web & Mobile
PDF
What is responsive - and do I need it?
PDF
Web apis JAX 2015 - Mainz
PDF
Web APIs - Mobiletech Conference 2015
PDF
Web APIs – expand what the Web can do
PDF
Firefox OS - A (mobile) Web Developers dream - DWX14
PDF
Firefox OS - A (web) developers dream - muxCamp 2014
PDF
Mozilla Brick - Frontend Rhein-Main June 2014
PDF
Traceur - Javascript.next - Now! RheinmainJS April 14th
State of Web APIs 2017
Headless in the CMS
Night Watch with QA
WebVR - MobileTechCon Berlin 2016
Evolution der Web Entwicklung
WebVR - JAX 2016
HTML5 Games for Web & Mobile
What is responsive - and do I need it?
Web apis JAX 2015 - Mainz
Web APIs - Mobiletech Conference 2015
Web APIs – expand what the Web can do
Firefox OS - A (mobile) Web Developers dream - DWX14
Firefox OS - A (web) developers dream - muxCamp 2014
Mozilla Brick - Frontend Rhein-Main June 2014
Traceur - Javascript.next - Now! RheinmainJS April 14th

Recently uploaded (20)

PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
Funds Management Learning Material for Beg
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPT
tcp ip networks nd ip layering assotred slides
PDF
Sims 4 Historia para lo sims 4 para jugar
DOCX
Unit-3 cyber security network security of internet system
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PPTX
innovation process that make everything different.pptx
international classification of diseases ICD-10 review PPT.pptx
The New Creative Director: How AI Tools for Social Media Content Creation Are...
RPKI Status Update, presented by Makito Lay at IDNOG 10
An introduction to the IFRS (ISSB) Stndards.pdf
Cloud-Scale Log Monitoring _ Datadog.pdf
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Introuction about WHO-FIC in ICD-10.pptx
Unit-1 introduction to cyber security discuss about how to secure a system
Job_Card_System_Styled_lorem_ipsum_.pptx
Funds Management Learning Material for Beg
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
presentation_pfe-universite-molay-seltan.pptx
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Decoding a Decade: 10 Years of Applied CTI Discipline
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
tcp ip networks nd ip layering assotred slides
Sims 4 Historia para lo sims 4 para jugar
Unit-3 cyber security network security of internet system
Triggering QUIC, presented by Geoff Huston at IETF 123
innovation process that make everything different.pptx

Always on! Or not?