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?
Susan Winters
 
PDF
Offline first, the painless way
Marcel Kalveram
 
PDF
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
Codemotion
 
PDF
How to make Ajax work for you
Simon Willison
 
PDF
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Simon Willison
 
PDF
APIs for modern web apps
Chris Mills
 
PPT
High Performance Ajax Applications
Julien Lecomte
 
PDF
Using Web Standards to create Interactive Data Visualizations for the Web
philogb
 
What is HTML 5?
Susan Winters
 
Offline first, the painless way
Marcel Kalveram
 
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
Codemotion
 
How to make Ajax work for you
Simon Willison
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Simon Willison
 
APIs for modern web apps
Chris Mills
 
High Performance Ajax Applications
Julien Lecomte
 
Using Web Standards to create Interactive Data Visualizations for the Web
philogb
 

What's hot (20)

PDF
[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager
DrupalDay
 
PPTX
High Performance JavaScript (CapitolJS 2011)
Nicholas Zakas
 
PPT
Going Offline with Gears And GWT
tom.peck
 
PDF
Everything is Awesome - Cutting the Corners off the Web
James Rakich
 
PDF
Easing offline web application development with GWT
Arnaud Tournier
 
PPTX
Ajax ppt - 32 slides
Smithss25
 
PDF
Dan Webb Presentation
RubyOnRails_dude
 
PPT
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
george.james
 
PDF
Instant and offline apps with Service Worker
Chang W. Doh
 
PDF
Keypoints html5
dynamis
 
PDF
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
IT Event
 
PPTX
Real World Lessons in Progressive Web Application & Service Worker Caching
Chris Love
 
PDF
The Complementarity of React and Web Components
Andrew Rota
 
PDF
Chrome enchanted 2015
Chang W. Doh
 
PDF
Ajax Security
Joe Walker
 
KEY
An Introduction to webOS
Kevin Decker
 
PDF
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
Robert Nyman
 
PDF
Choosing a Javascript Framework
All Things Open
 
PPT
WordPress and Ajax
Ronald Huereca
 
PDF
Introduction to Node.js
Aaron Rosenberg
 
[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager
DrupalDay
 
High Performance JavaScript (CapitolJS 2011)
Nicholas Zakas
 
Going Offline with Gears And GWT
tom.peck
 
Everything is Awesome - Cutting the Corners off the Web
James Rakich
 
Easing offline web application development with GWT
Arnaud Tournier
 
Ajax ppt - 32 slides
Smithss25
 
Dan Webb Presentation
RubyOnRails_dude
 
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
george.james
 
Instant and offline apps with Service Worker
Chang W. Doh
 
Keypoints html5
dynamis
 
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
IT Event
 
Real World Lessons in Progressive Web Application & Service Worker Caching
Chris Love
 
The Complementarity of React and Web Components
Andrew Rota
 
Chrome enchanted 2015
Chang W. Doh
 
Ajax Security
Joe Walker
 
An Introduction to webOS
Kevin Decker
 
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
Robert Nyman
 
Choosing a Javascript Framework
All Things Open
 
WordPress and Ajax
Ronald Huereca
 
Introduction to Node.js
Aaron Rosenberg
 
Ad

Similar to Always on! Or not? (20)

PDF
Always on! ... or not?
Carsten Sandtner
 
PDF
Web APIs & Apps - Mozilla
Robert Nyman
 
PDF
Exploring pwa for shopware
Sander Mangel
 
PDF
AFUP Lorraine - Symfony Webpack Encore
Engineor
 
PDF
Rapid Application Development with WSO2 Platform
WSO2
 
PDF
WebAPIs & Apps - Mozilla London
Robert Nyman
 
PDF
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
PDF
(2018) Webpack Encore - Asset Management for the rest of us
Stefan Adolf
 
PDF
RESTful Web Applications with Apache Sling
Bertrand Delacretaz
 
PDF
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
PDF
Get Ahead with HTML5 on Moible
markuskobler
 
PDF
HTML5 tutorial: canvas, offfline & sockets
Remy Sharp
 
PDF
Empowering the "mobile web"
Chris Mills
 
PDF
Empowering the Mobile Web - Mills
Codemotion
 
PDF
Empowering the “Mobile Web” with Chris Mills
FITC
 
PDF
Web Apps and more
Yan Shi
 
PDF
Web app and more
faming su
 
PDF
Apache cordova
Carlo Bernaschina
 
PPTX
Html5
Zahin Omar Alwa
 
KEY
Developing High Performance Web Apps - CodeMash 2011
Timothy Fisher
 
Always on! ... or not?
Carsten Sandtner
 
Web APIs & Apps - Mozilla
Robert Nyman
 
Exploring pwa for shopware
Sander Mangel
 
AFUP Lorraine - Symfony Webpack Encore
Engineor
 
Rapid Application Development with WSO2 Platform
WSO2
 
WebAPIs & Apps - Mozilla London
Robert Nyman
 
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
(2018) Webpack Encore - Asset Management for the rest of us
Stefan Adolf
 
RESTful Web Applications with Apache Sling
Bertrand Delacretaz
 
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
Get Ahead with HTML5 on Moible
markuskobler
 
HTML5 tutorial: canvas, offfline & sockets
Remy Sharp
 
Empowering the "mobile web"
Chris Mills
 
Empowering the Mobile Web - Mills
Codemotion
 
Empowering the “Mobile Web” with Chris Mills
FITC
 
Web Apps and more
Yan Shi
 
Web app and more
faming su
 
Apache cordova
Carlo Bernaschina
 
Developing High Performance Web Apps - CodeMash 2011
Timothy Fisher
 
Ad

More from Carsten Sandtner (15)

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

Recently uploaded (20)

PPTX
Black Yellow Modern Minimalist Elegant Presentation.pptx
nothisispatrickduhh
 
PPTX
LESSON-2-Roles-of-ICT-in-Teaching-for-learning_123922 (1).pptx
renavieramopiquero
 
PPTX
Different Generation Of Computers .pptx
divcoder9507
 
PDF
Generative AI Foundations: AI Skills for the Future of Work
hemal sharma
 
PDF
KIPER4D situs Exclusive Game dari server Star Gaming Asia
hokimamad0
 
PPTX
dns domain name system history work.pptx
MUHAMMADKAVISHSHABAN
 
PPTX
ppt lighfrsefsefesfesfsefsefsefsefserrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrt.pptx
atharvawafgaonkar
 
PPTX
Artificial-Intelligence-in-Daily-Life (2).pptx
nidhigoswami335
 
PDF
LOGENVIDAD DANNYFGRETRRTTRRRTRRRRRRRRR.pdf
juan456ytpro
 
PPTX
谢尔丹学院毕业证购买|Sheridan文凭不见了怎么办谢尔丹学院成绩单
mookxk3
 
PDF
DNSSEC Made Easy, presented at PHNOG 2025
APNIC
 
PPTX
B2B_Ecommerce_Internship_Simranpreet.pptx
LipakshiJindal
 
PPTX
Pengenalan perangkat Jaringan komputer pada teknik jaringan komputer dan tele...
Prayudha3
 
PPTX
Parallel & Concurrent ...
yashpavasiya892
 
PPT
Transformaciones de las funciones elementales.ppt
rirosel211
 
PDF
Latest Scam Shocking the USA in 2025.pdf
onlinescamreport4
 
PDF
UI/UX Developer Guide: Tools, Trends, and Tips for 2025
Penguin peak
 
PPTX
Crypto Recovery California Services.pptx
lionsgate network
 
PPTX
EthicalHack{aksdladlsfsamnookfmnakoasjd}.pptx
dagarabull
 
PPTX
The Latest Scam Shocking the USA in 2025.pptx
onlinescamreport4
 
Black Yellow Modern Minimalist Elegant Presentation.pptx
nothisispatrickduhh
 
LESSON-2-Roles-of-ICT-in-Teaching-for-learning_123922 (1).pptx
renavieramopiquero
 
Different Generation Of Computers .pptx
divcoder9507
 
Generative AI Foundations: AI Skills for the Future of Work
hemal sharma
 
KIPER4D situs Exclusive Game dari server Star Gaming Asia
hokimamad0
 
dns domain name system history work.pptx
MUHAMMADKAVISHSHABAN
 
ppt lighfrsefsefesfesfsefsefsefsefserrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrt.pptx
atharvawafgaonkar
 
Artificial-Intelligence-in-Daily-Life (2).pptx
nidhigoswami335
 
LOGENVIDAD DANNYFGRETRRTTRRRTRRRRRRRRR.pdf
juan456ytpro
 
谢尔丹学院毕业证购买|Sheridan文凭不见了怎么办谢尔丹学院成绩单
mookxk3
 
DNSSEC Made Easy, presented at PHNOG 2025
APNIC
 
B2B_Ecommerce_Internship_Simranpreet.pptx
LipakshiJindal
 
Pengenalan perangkat Jaringan komputer pada teknik jaringan komputer dan tele...
Prayudha3
 
Parallel & Concurrent ...
yashpavasiya892
 
Transformaciones de las funciones elementales.ppt
rirosel211
 
Latest Scam Shocking the USA in 2025.pdf
onlinescamreport4
 
UI/UX Developer Guide: Tools, Trends, and Tips for 2025
Penguin peak
 
Crypto Recovery California Services.pptx
lionsgate network
 
EthicalHack{aksdladlsfsamnookfmnakoasjd}.pptx
dagarabull
 
The Latest Scam Shocking the USA in 2025.pptx
onlinescamreport4
 

Always on! Or not?