SlideShare a Scribd company logo
Always ON!
…or not?
Carsten Sandtner (@casarock)
mediaman// Gesellschaft für Kommunikation mbH
about:me
Carsten Sandtner
@casarock
Head of Software Development
//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
AppCache: Definition
<!DOCTYPE html>
<html lang="en" manifest="cache.manifest">
AppCache: Manifest
CACHE MANIFEST
# v2 2016-09-30
index.html
cache.html
style.css
app.js
hero.png
# Use from network if available
NETWORK:
network.html
# Fallback content
FALLBACK:
/ fallback.html
AppCache: Javascript
window.applicationCache.onchecking = function(e) {}
window.applicationCache.onnoupdate = function(e) {}
window.applicationCache.onupdateready = function(e) {}
window.applicationCache.onobsolete = function(e) {}
window.applicationCache.ondownloading = function(e) {}
window.applicationCache.oncached = function(e) {}
window.applicationCache.onerror = function(e) {}
window.applicationCache.onprogress = function(e) {}
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…
„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
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!
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
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

PDF
Web APIs & Apps - Mozilla
PDF
Web Apps and more
PDF
Modern JavaScript Frameworks: Angular, React & Vue.js
PDF
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
PDF
Mobile Web & HTML5 Performance Optimization
PDF
The Future Of Web Frameworks
PDF
Progressive Enhancement 2.0 (Conference Agnostic)
PPTX
What is HTML 5?
Web APIs & Apps - Mozilla
Web Apps and more
Modern JavaScript Frameworks: Angular, React & Vue.js
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
Mobile Web & HTML5 Performance Optimization
The Future Of Web Frameworks
Progressive Enhancement 2.0 (Conference Agnostic)
What is HTML 5?

What's hot (17)

PDF
FEDM Meetup: Introducing Mojito
PDF
APIs, now and in the future
PDF
Empowering the "mobile web"
PDF
Frontend Monoliths: Run if you can!
PDF
Web versus Native: round 1!
PDF
Real World Progressive Web Apps (Building Flipkart Lite)
PPTX
Browser Wars Episode 1: The Phantom Menace
PPTX
HTML5 WebWorks
PPTX
Disrupting the application eco system with progressive web applications
PDF
APIs for modern web apps
PDF
Frontend. Global domination.
PDF
Building Progressive Web Apps for Android and iOS
PDF
Rails for Mobile Devices @ Conferencia Rails 2011
PDF
Keypoints html5
PPTX
Building SPA’s (Single Page App) with Backbone.js
PDF
Building Mobile Applications with Ionic
PDF
JavaScript Libraries: The Big Picture
FEDM Meetup: Introducing Mojito
APIs, now and in the future
Empowering the "mobile web"
Frontend Monoliths: Run if you can!
Web versus Native: round 1!
Real World Progressive Web Apps (Building Flipkart Lite)
Browser Wars Episode 1: The Phantom Menace
HTML5 WebWorks
Disrupting the application eco system with progressive web applications
APIs for modern web apps
Frontend. Global domination.
Building Progressive Web Apps for Android and iOS
Rails for Mobile Devices @ Conferencia Rails 2011
Keypoints html5
Building SPA’s (Single Page App) with Backbone.js
Building Mobile Applications with Ionic
JavaScript Libraries: The Big Picture
Ad

Similar to Always on! ... or not? (20)

PDF
Always on! Or not?
PPTX
PWA basics for developers
PDF
Velocity EU 2014 — Offline-first web apps
PDF
A year with progressive web apps! #DevConMU
PDF
Offline progressive web apps with NodeJS and React
PDF
Angular Offline Progressive Web Apps With NodeJS
PDF
Service workers are your best friends
PDF
Front-end. Global domination
PDF
JavaScript Service Worker Design Patterns for Better User Experience
PPTX
Progressive web applications
PDF
Service worker API
PDF
Progressive Web Apps
PDF
A year with progressive web apps! #webinale
PDF
"Progressive Web Apps" by Riza Fahmi (Hacktiv8)
PDF
Progressive Web Apps. What, why and how
PDF
Web fundamentals
PDF
Stop the internet, i want to go offline
PPTX
Raising ux bar with offline first design
PDF
Web is the New Mobile: Building Progressive Web Apps - Erica Stanley - Codemo...
Always on! Or not?
PWA basics for developers
Velocity EU 2014 — Offline-first web apps
A year with progressive web apps! #DevConMU
Offline progressive web apps with NodeJS and React
Angular Offline Progressive Web Apps With NodeJS
Service workers are your best friends
Front-end. Global domination
JavaScript Service Worker Design Patterns for Better User Experience
Progressive web applications
Service worker API
Progressive Web Apps
A year with progressive web apps! #webinale
"Progressive Web Apps" by Riza Fahmi (Hacktiv8)
Progressive Web Apps. What, why and how
Web fundamentals
Stop the internet, i want to go offline
Raising ux bar with offline first design
Web is the New Mobile: Building Progressive Web Apps - Erica Stanley - Codemo...
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)

PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PDF
Testing WebRTC applications at scale.pdf
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
Funds Management Learning Material for Beg
DOCX
Unit-3 cyber security network security of internet system
PPTX
Introduction to Information and Communication Technology
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
innovation process that make everything different.pptx
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
Internet___Basics___Styled_ presentation
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PptxGenJS_Demo_Chart_20250317130215833.pptx
Testing WebRTC applications at scale.pdf
Sims 4 Historia para lo sims 4 para jugar
Paper PDF World Game (s) Great Redesign.pdf
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Decoding a Decade: 10 Years of Applied CTI Discipline
Unit-1 introduction to cyber security discuss about how to secure a system
Funds Management Learning Material for Beg
Unit-3 cyber security network security of internet system
Introduction to Information and Communication Technology
An introduction to the IFRS (ISSB) Stndards.pdf
RPKI Status Update, presented by Makito Lay at IDNOG 10
Module 1 - Cyber Law and Ethics 101.pptx
introduction about ICD -10 & ICD-11 ppt.pptx
innovation process that make everything different.pptx
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Internet___Basics___Styled_ presentation

Always on! ... or not?