SlideShare a Scribd company logo
Offline-First
The painless way
Who is this guy?
MarcelKalveram
IWorkatHanno
Iamfromgermany
ILiveinValencia/Spain
javaScript’ingsincearound2008
RemoteUXTeam
weworkwithstartups
socialbusiness
hanno.co
@wearehanno
@marcelkalveram
Do we really need offline-first?
Traveling Commuting
Roaming Internetoutage saturatednetwork
Offline first, the painless way
What does offline-first mean?
Tomanagedatainanappinsuchaway
thatwedon'tneedserveraccessinorderto
doanykindofoperation
some well-considered
s
What is this talk about?
Native
apps
Web
sites
Web apps
Look stuff upDo stuff
When does it make sense?
content-heavysites(Nativeapps)
singlepagewebapps
staticsites
real-timeapps
self-containedapps
not our business
What are the benefits?
Nodata-lossfortheuser
Offline-firstappsarefaster…
appsareusableallthetime
HOW
to do offline-first…?
Offline challenges
cachingdynamicassets
Cachingstaticassets
PrepareUIforofflinestate
xhr, remote api calls
.json, .xml, .csv
xhr, remote api calls
Caching mechanisms
staticdata dynamicdata
page assets
.html, .css, .jpg, .js, .ttf
page assets
browsercache
serviceworkers
appcache
vs.
indexedDB
webSql
webstorage
browsercache
serviceworkers
appcache
Caching mechanisms
can’t trust him-
lack of browser support-
staticdata
page assets
.html, .css, .jpg, .js, .ttf
page assets
indexedDB
webSql
webstorage
Caching mechanisms
localforage
pouchDB
}lack of browser support -
api is overly complex -
dynamicdata
xhr, remote api calls
.json, .xml, .csv
xhr, remote api calls
Challenge #1
Caching static assets
App cache
appcache
intercepts http request
manifestfile
<html manifest="my.appcache">
cache,networkandfallback user
browser
returns cached data
server
server
App cache
cache,networkandfallback
resources can be
used offline.
online whitelist substitute non-
cached resources
appcache
user
browser
app.js
image.png
font.ttf
Manifestr
js
*
cache
network
fallback
-
App cache gotchas
1.filesalwayscomefromthecache
server side generated websites
single page applications
2.onlyupdatesifmanifestfilechange
3.needtoswapthecachemanually
serverappcache
user
browser
applicationCache.swapCache();
Browser support for…appcache
10+ 4+ 3.5+4+ 2.1+ 3.2+
Browser support for…service workers
n/a n/a n/a40+ n/a n/a
Challenge #2
caching dynamic assets
Caching mechanisms
dynamicdata
xhr, remote api calls
.json, .xml, .csv
xhr, remote api calls
indexedDB
webSql
webstorage
localforage
pouchDB
}lack of browser support -
api is overly complex -
Using web storage
no online
connection required
sessionstorage or localstorage
key/value store
appcachestorage
user
browser
Using web storage APIs
currentHighscore
lastMove
levelsCompleted
1890
D4E5
12
keys values
Using web storage APIs
localStorage.setItem("lastMove", "D4E5");
localStorage.getItem("levelsCompleted");
currentHighscore
lastMove
levelsCompleted
1890
D4E5
12
Browser support for…localstorage
8+ 3.5+ 4+4+ 2.1+ 3.2+
asynchronous
Why don’t we just use…indexedDB?
webstorage indexedDB
synchronous
limited to strings supports large data sets
no indexes indexes
10mb storage 50mb storage
Browser support for…indexedDB?
*Subfeatures not supported
**buggy behavior in iOS8
10+ 10+ 7.1+23+ 4.4+ 8+* **
Browser support for… webSQL?
*is no longer being maintained
*
n/a n/a 3.1+4+ 2.1+ 3.2+
browser APIs…
localStorage
webSql
indexedDB
limited storage options
lack of browser support
overly complex api
localForage…
…limitationsoflocalStorage
helps us overcome
…browserdifferences
supports all js objects
asynchronous
indexedDB, webSQL and localstorage
loads best driver for us
json
currentHighscore
lastMove
levelsCompleted
1890
12
localForage
localForage.setItem("lastMove", incrediblyComplexJsonObject)
localForage.getItem("levelsCompleted", function(err, val) {…});
takes care of
(de-)serialization
.then(…)
supports promises
https://github.com/mozilla/localForage
What about syncing?
localstorage
indexedDB
localforage
our responsibility
What about syncing?
localstorage
indexedDB
localforage
pouchDB
our responsibility
object
pouchDB API
pdb.put(o, cb) pdb.get(id, cb)
currentHighscore
lastMove
levelsCompleted
1890
12
_id: "lastMove",
lastPos: "D4"
newPos: "E5"
"lastMove"
pouchDB sync
pdb.sync(remoteDB);
new PouchDB("http://localhost:5984/myremotedb")
https://github.com/pouchdb/pouchdb
Challenge #3
preparing our ui
yes
no
no
yes
ami
online…
doihave
updates…
syncwith
server
offline
app
store
locally
How to detect online status
1
navigator
events
2
appcache
events
3
xhr
events
Navigator events
window.addEventListener("online", function(e) {alert("online");})
online/offline
navigator.onLine
true/false
Navigator events
is always onlineworks only
in offline-modeshows online even if
connection is unreliable
Appcache events
applicationCache.addEventListener("error", function(e) { … });
checking progress
cached
error
XHR events
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e) {
}
if (xhr.status != 200) {
}
thereisprobablyaconnectionissue
https://github.com/HubSpot/offline
static and dynamic data
with remote server
what to take offline
if offline-first makes sense
useevents
prepareui for flawless user experience
consider
decide
to detect offline state
cache
sync
with your users
some good in the world
empathize
Do
Thanks!
hanno.co

More Related Content

PPTX
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
PDF
PDF
system-design-interview-an-insiders-guide-2nbsped-9798664653403.pdf
PPT
Native, Web or Hybrid Mobile App Development?
PPTX
Google Chrome DevTools features overview
PDF
'From Client Side To Critical' By Kuldeep Pandya And Satyam Gothi - Bsides 2024
PDF
Building a Microservices-based ERP System
PPTX
Android task manager project presentation
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
system-design-interview-an-insiders-guide-2nbsped-9798664653403.pdf
Native, Web or Hybrid Mobile App Development?
Google Chrome DevTools features overview
'From Client Side To Critical' By Kuldeep Pandya And Satyam Gothi - Bsides 2024
Building a Microservices-based ERP System
Android task manager project presentation

What's hot (20)

PPTX
IndexedDB - An Efficient Way to Manage Data
PPTX
Hibernate Basic Concepts - Presentation
PPTX
NameNode Analytics - Querying HDFS Namespace in Real Time
PDF
Spring Data JPA
PDF
HBase for Architects
ODP
Groovy AST Transformations
PDF
Sqoop on Spark for Data Ingestion
PPTX
SOA with PHP and Symfony
PDF
The Log4Shell Vulnerability – explained: how to stay secure
PPTX
Spark rdd vs data frame vs dataset
PDF
Introduction to the Hadoop Ecosystem with Hadoop 2.0 aka YARN (Java Serbia Ed...
PDF
Trino: A Ludicrously Fast Query Engine - Pulsar Summit NA 2021
PDF
Optimizing Hive Queries
PDF
Java Performance Analysis on Linux with Flame Graphs
PDF
Log4j in 8 slides
PPTX
Spark Tips & Tricks
PPTX
Invoke-Obfuscation nullcon 2017
PDF
大数据时代feed架构 (ArchSummit Beijing 2014)
PPTX
Architectural changes in the repo in 6.1 and beyond
PDF
Google Cloud Dataflow
IndexedDB - An Efficient Way to Manage Data
Hibernate Basic Concepts - Presentation
NameNode Analytics - Querying HDFS Namespace in Real Time
Spring Data JPA
HBase for Architects
Groovy AST Transformations
Sqoop on Spark for Data Ingestion
SOA with PHP and Symfony
The Log4Shell Vulnerability – explained: how to stay secure
Spark rdd vs data frame vs dataset
Introduction to the Hadoop Ecosystem with Hadoop 2.0 aka YARN (Java Serbia Ed...
Trino: A Ludicrously Fast Query Engine - Pulsar Summit NA 2021
Optimizing Hive Queries
Java Performance Analysis on Linux with Flame Graphs
Log4j in 8 slides
Spark Tips & Tricks
Invoke-Obfuscation nullcon 2017
大数据时代feed架构 (ArchSummit Beijing 2014)
Architectural changes in the repo in 6.1 and beyond
Google Cloud Dataflow
Ad

Viewers also liked (20)

PDF
Offline-First Apps with PouchDB
PPTX
Couch DB/PouchDB approach for hybrid mobile applications
PDF
Pouch db tdc2016
PPTX
Easy offline-first mobile and desktop web apps with PouchDB
PDF
Apache CouchDB
DOCX
DOCX
Realism, heroism, bravery, boldness or cowardice
PPTX
C:\Documents And Settings\Administrator\Desktop\Why Everyone Should Learn Cpr
PPTX
Private Engineering Colleges in Gurgaon
DOC
Zaragoza turismo 204
PPTX
Welcome talent - create a great LinkedIn profile
PPTX
Search Marketing for Business to Business
PPS
Reality
PDF
Longnow 16 Jan 09
PPS
美國暢銷書第一名
ODP
Career Guidance In Engineering - Dronacharya
PPT
Honors ~ Dna 1314
PDF
Mamona presentation at linuxtag
PPTX
Using Social Media for Collaboration
PPS
Cezanne Paule
Offline-First Apps with PouchDB
Couch DB/PouchDB approach for hybrid mobile applications
Pouch db tdc2016
Easy offline-first mobile and desktop web apps with PouchDB
Apache CouchDB
Realism, heroism, bravery, boldness or cowardice
C:\Documents And Settings\Administrator\Desktop\Why Everyone Should Learn Cpr
Private Engineering Colleges in Gurgaon
Zaragoza turismo 204
Welcome talent - create a great LinkedIn profile
Search Marketing for Business to Business
Reality
Longnow 16 Jan 09
美國暢銷書第一名
Career Guidance In Engineering - Dronacharya
Honors ~ Dna 1314
Mamona presentation at linuxtag
Using Social Media for Collaboration
Cezanne Paule
Ad

Similar to Offline first, the painless way (20)

PDF
The Hitchhikers Guide To Html5 Offline Strategies (+firefoxOS)
PDF
Offline Strategies for HTML5 Web Applications - oscon13
PDF
Velocity EU 2014 — Offline-first web apps
PDF
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
PPTX
Offline Webapps
PPTX
Raising ux bar with offline first design
PDF
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
 
PDF
your browser, my storage
PDF
Offline browser testing
PDF
Always on! ... or not?
PPTX
Academy PRO: HTML5 Data storage
PDF
Your browser, your storage (extended version)
PDF
Naked and afraid Offline Mobile
PDF
Naked and afraid Offline mobile
PPT
HTML 5 Offline Web apps
PDF
Offline strategies for HTML5 web applications - ConFoo13
PDF
Offline strategies for HTML5 web applications - IPC12
PDF
Taking Web Apps Offline
PDF
Easy Data for PhoneGap apps with PouchDB
PDF
Offline strategies for HTML5 web applications - pfCongres2012
The Hitchhikers Guide To Html5 Offline Strategies (+firefoxOS)
Offline Strategies for HTML5 Web Applications - oscon13
Velocity EU 2014 — Offline-first web apps
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
Offline Webapps
Raising ux bar with offline first design
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
 
your browser, my storage
Offline browser testing
Always on! ... or not?
Academy PRO: HTML5 Data storage
Your browser, your storage (extended version)
Naked and afraid Offline Mobile
Naked and afraid Offline mobile
HTML 5 Offline Web apps
Offline strategies for HTML5 web applications - ConFoo13
Offline strategies for HTML5 web applications - IPC12
Taking Web Apps Offline
Easy Data for PhoneGap apps with PouchDB
Offline strategies for HTML5 web applications - pfCongres2012

Recently uploaded (20)

PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPT
tcp ip networks nd ip layering assotred slides
PPTX
artificial intelligence overview of it and more
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
Digital Literacy And Online Safety on internet
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
The Internet -By the Numbers, Sri Lanka Edition
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
Introduction to Information and Communication Technology
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
innovation process that make everything different.pptx
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
RPKI Status Update, presented by Makito Lay at IDNOG 10
tcp ip networks nd ip layering assotred slides
artificial intelligence overview of it and more
Unit-1 introduction to cyber security discuss about how to secure a system
Decoding a Decade: 10 Years of Applied CTI Discipline
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
Digital Literacy And Online Safety on internet
Slides PPTX World Game (s) Eco Economic Epochs.pptx
The Internet -By the Numbers, Sri Lanka Edition
Introuction about WHO-FIC in ICD-10.pptx
Introuction about ICD -10 and ICD-11 PPT.pptx
Introduction to Information and Communication Technology
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
international classification of diseases ICD-10 review PPT.pptx
Slides PDF The World Game (s) Eco Economic Epochs.pdf
WebRTC in SignalWire - troubleshooting media negotiation
innovation process that make everything different.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Design_with_Watersergyerge45hrbgre4top (1).ppt

Offline first, the painless way