SlideShare ist ein Scribd-Unternehmen logo
1 von 67
1
November 13, 2017
Raising UX bar with Offline-
First Design
Kyrylo Reznykov
2
Agenda
● Why Do We Need Offline-First Design?
● Browser APIs Essential For Reliable Web
Apps.
● The Most Common UI/UX Patterns.
● Offline Storage With Replication to a Server.
● Challenges when you build Offline-First Apps.
3
Why Do We Need Offline-First Design?
4
What is common in two places?
Subway, New York
Celentano Pizza, Lviv
5
Both places don’t have network coverage
6
The are a lot of situations without connection
7
Also internet is extremely slow in some places
Today, 60% of
mobile internet
users have only 2g
connection speeds.
8
UX when your apps don’t care about offline
Saving
9
Users see web as unstable platform
10
Data shows that they prefer mobile apps
11
Web has evolved and ready to compete with native apps
Pros (compare to native apps):
● No installation.
● It may take less space.
● Web apps are way more secure
12
Web has evolved and ready to compete with native apps
Pros (compare to native apps):
● No installation.
● It may take less space.
● Web apps are way more secure
Cons:
● Lower performance
● Less APIs available.
13
Browser APIs Essential For Reliable
Web Apps.
14
HTML5 Application Cache
Pros:
Extremely easy to use.
Older browsers support it, only option in IE 10 & IE 11.
Cons:
Can be served over insecure HTTP.
Lacks flexibility.
Will be removed soon in new browsers.
<html manifest="cache.mf">
...
CACHE MANIFEST
style.css
image.png
# Use from network if available
NETWORK:
list.json
FALLBACK:
example/bar/ example.html
15
Service Worker API
Service worker can handle events even when browser is closed!
Browser
16
Service Worker API Support
In 2018 every major browser will support SW.
17
Service Worker Lifecycle
Register:
navigator.serviceWorker.register('/sw.js') // path is a scope
.then(reg => console.log('SW registered!', reg));
!! Serve sw.js with Cache-Control: max-age=0
18
Service Worker Lifecycle
Register:
navigator.serviceWorker.register('/sw.js') // path is a scope
.then(reg => console.log('SW registered!', reg));
!! Serve sw.js with Cache-Control: max-age=0
19
Service Worker Lifecycle
Register:
navigator.serviceWorker.register('/sw.js') // path is a scope
.then(reg => console.log('SW registered!', reg));
!! Serve sw.js with Cache-Control: max-age=0
20
Service Worker Install Event
const cacheCriticals = () => {
return caches.open(CACHE_NAME).then(cache => {
// important, but not critical
cache.addAll(resourcesToCache);
// critical resources
return cache.addAll(criticalResources);
});
};
self.addEventListener('install', function (installEvent) {
installEvent.waitUntil(cacheCriticals());
});
21
Service Worker Activate Event
function cleanup(cacheNames) {
return Promise.all(
cacheNames.filter(function (cacheName) {
return cacheName !== CACHE_NAME;
}).map(function (cacheName) {
return caches.delete(cacheName);
})
);
}
self.addEventListener('activate', function(event) {
event.waitUntil(caches.keys().then(cleanup));
});
*Old service worker is paused at that moment. Fetch requests will be added to queue..
22
Service Worker Fetch Event
self.addEventListener('fetch', function(event) {
// magic goes here
});
*The request is attended by the most specific SW only.
23
Service Worker Fetch Event
self.addEventListener('fetch', function(event) {
event.respondWith(fetch(event.request));
});
*The request is attended by the most specific SW only.
24
const getCachedOrFetch = function (event) {
return caches.match(event.request)
.then(response => response || fetch(event.request));
}
self.addEventListener('fetch', function(event) {
event.respondWith(getCachedOrFetch(event));
});
Service Worker Fetch Event
25
Don’t write boilerplate use
Workbox
26
Workbox
Offline Caching:
● Cache only
● Cache first, falling back to network
● Cache, with network update
● Network only
● Network first, falling back to cache
Offline Analytics:
Workbox can collect user analytics while offline.
27
Workbox
You can integrate it with:
28
Workbox
You can integrate it with:
Or use it directly in the service worker:
//synchronously imports scripts into the worker's scope
importScripts('/node_modules/workbox-sw/build/workbox-sw.vX.X.X.prod.js');
const workboxSW = new WorkboxSW();
const networkFirst = workboxSW.strategies.networkFirst();
workboxSW.router.registerRoute('/schedule', networkFirst);
29
BackgroundSync DEMO
Service Worker Background Sync
// sync will fire when the user agent believes the user has connectivity
self.addEventListener('sync', function(event) {
if (event.tag === ‘anyTag’) event.waitUntil(doWhatYouWant());
});
Finally, we have a better option than WindowEventHandlers.onbeforeunload
30
Browser Storage APIs
Cache API (part of Service Worker). - use it for URL addressable resources.
31
Browser Storage APIs
Cache API (part of Service Worker). - use it for URL addressable resources.
IndexedDB - use it for all other data. (Also, exist polyfills with fallback to Web
SQL).
32
Browser Storage APIs
Cache API (part of Service Worker). - use it for URL addressable resources.
IndexedDB - use it for all other data. (Also, exist polyfills with fallback to Web
SQL).
LocalStorage - Has no Web Worker. But it is persistent storage by default!
33
Browser Storage APIs
Cache API (part of Service Worker). - use it for URL addressable resources.
IndexedDB - use it for all other data. (Also, exist polyfills with fallback to Web
SQL).
LocalStorage - Has no Web Worker. But it is persistent storage by default!
Space available to origin is shared between all forms of storage above.
There is no standard way to check quota. We have two
experimental APIs: Quota Management API and Storage
Manager API.
34
How much can I store?
35
Be Aware of Cache Eviction in Browsers
*If app is not installed by user (Chrome, FF) or don’t have
high engagement.
Chrome LRU once Chrome runs out of
space
Firefox LRU if the whole disk gets full
Safari & Edge No cache eviction
!! It includes Indexed DB and Cache API.
36
Be Aware of Cache Eviction in Browsers
*If app is not installed by user (Chrome, FF) or don’t have
high engagement.
Chrome LRU once Chrome runs out of
space
Firefox LRU if the whole disk gets full
Safari & Edge No cache eviction
!! It includes Indexed DB, Cache API.
navigator.storage.persist().then(function(isPersistent) {
// isPersistent will be true if user allowed
})
37
UI/UX patterns
38
● Try to provide offline by default if your app doesn't
require much data.
● Treat a connection to the internet as an enhancement
instead of a dependency
● Use optimistic UI approach if possible.
● User must be properly notified about app state.
● Use save for offline button
● Precache things that needed with high probability
offline especially if they are small
Core ideas
39
Connection is enhancement not a dependency
You can create new google doc while you offline.
Once we connect to internet it will be synced.
40
Use optimistic ui approach if possible
avoid that approach
if possible
If we offline, sync that action later.
41
User must be properly notified about app state
42
Use save for offline button
Especially important
approach for content
oriented applications
like:
● Spotify
● Google maps
● Web readers
● e.t.c
43
Cache things automatically
● Do you users often use that
feature?
● Can it be useful offline?
● Is it lightweight?
● Is it not sensitive data?
If answer yes for all
Pre-cache it without asking.
44
Offline Storage Replication
45
We are writing distributed system
46
The CAP Theorem
You can have at
most two of these
properties for any
shared-data
system
47
Offline-First apps needs AP to work
We need to
sacrifice strong
consistency
between nodes in
favour of high
availability of data
48
Already we have a lot of different solutions for that
49
PouchDB + CouchDB
CouchDB is was designed from the bottom-up to
enable easy synchronization between databases.
{
"_id": "any_string",
"_rev": "1-bea5fa18e06522d12026f4aee6b15ee4"
"name": "John",
...
}
50
PouchDB + CouchDB
Pros:
● Production ready. Well tested
● Nice documentation.
● Wide browser support.
Cons
● You are tight to a specific DB which supports its sync
protocol on backend.
● Poor automatic conflict resolution*
● Not good for real time apps.
*The winner is the version with the longest revision history
And in case of a tie, the winner is the revision with the lexicographically highest
revision ID; e.g. "12-F4B2..." beats "12-42AA..."
51
Face of average user if you ask him to resolve conflicts
52
Would be nice to have automated resolver
53
Would be nice to have automated resolver
54
CRDT to the rescue
55
Bob
Example, why CRDT works
John
56
Example, why CRDT works
Bob
John
57
Example, why CRDT works
Bob
John
58
More about CRDT
Well known CRDTs
● G-Counter (Grow-only Counter)
● PN-Counter (Positive-Negative Counter)
● G-Set (Grow-only Set, which only allows adding)
● 2P-Set (Two-Phase Set, remove-wins" set)
● LWW-Element-Set (Last-Write-Wins-Element-Set)
● e.t.c
CRDT provides strong eventual consistency (SEC)
It means that if all nodes get all updates in whatever order they will come to
the same state. If you use inappropriate type you may get messy state, although it will be
consistent across app.
59
CRDT is not a silver bullet
Cannot model every data type..
60
Swarm.js
Pros
● Real time replication
● Automatic conflict resolution
● Need little data to transfer (CmRDT)
Cons
● It is kind of research project
● Almost no documentation
● Vague future
61
Logux
Pros
● In active development
● Very flexible
● Redux API
● Foundation for CRDT
Cons
● Very young project
Library inspired by Redux and Swarm.js
62
Gun.js
Pros
● In active development
● With real time in mind
● Looks like best open source solution
● Integrates with different Backend DBs
Cons
● Not mature enough
63
Challenges when you build Offline-
First Apps.
64
- Some useful API still not standardized
- Find security/convenience ballance.
- Handling multiple users on one machine.
- Educate through UI users about what is working offline
- Wise Caching. (Do not force user to download whole
site on first visit.)
- Mobile traffic costs a lot in some places.
- Data synchronization tools is quite immature.
- New auto testing challenges (Panic Server)
Challenges when you build Offline-First Apps
65
PWA expansion around the world
66
More to read
- Repository with with information related to offline-first apps
- Problems of AppCache
- About Service Workers
- Is Service Worker Ready
- Read more about Workbox
- Good Article About Optimistic UI
- Complete Gun.js tutorial
- Read blog of Swarm.js developer
- More About Logux: YouTube Video
- CRDT original paperwork
- Security thoughts about offline apps
- Unit-testing-service-worker
- Background Sync
- My Offline-First App (Slightly Unfinished)
67
Thank you for your attention

Weitere ähnliche Inhalte

Was ist angesagt?

Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And Tricks
Mike Hugo
 

Was ist angesagt? (20)

My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
 
Lucio Grenzi - Building serverless applications on the Apache OpenWhisk platf...
Lucio Grenzi - Building serverless applications on the Apache OpenWhisk platf...Lucio Grenzi - Building serverless applications on the Apache OpenWhisk platf...
Lucio Grenzi - Building serverless applications on the Apache OpenWhisk platf...
 
Regex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadRegex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language Instead
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And Tricks
 
Apache Lucene for Java EE Developers
Apache Lucene for Java EE DevelopersApache Lucene for Java EE Developers
Apache Lucene for Java EE Developers
 
Ratpack Web Framework
Ratpack Web FrameworkRatpack Web Framework
Ratpack Web Framework
 
Reactive Applications with Apache Pulsar and Spring Boot
Reactive Applications with Apache Pulsar and Spring BootReactive Applications with Apache Pulsar and Spring Boot
Reactive Applications with Apache Pulsar and Spring Boot
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
 
Weaving Through the Mesh: Making Sense of Istio and Overlapping Technologies
Weaving Through the Mesh: Making Sense of Istio and Overlapping TechnologiesWeaving Through the Mesh: Making Sense of Istio and Overlapping Technologies
Weaving Through the Mesh: Making Sense of Istio and Overlapping Technologies
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Preparing your code for Java 9
Preparing your code for Java 9Preparing your code for Java 9
Preparing your code for Java 9
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
Smart Gamma - Real-Time Web applications with PHP and Websocket.
Smart Gamma - Real-Time Web applications with PHP and Websocket.Smart Gamma - Real-Time Web applications with PHP and Websocket.
Smart Gamma - Real-Time Web applications with PHP and Websocket.
 
Lightning talk: 12 Factor Containers
Lightning talk: 12 Factor ContainersLightning talk: 12 Factor Containers
Lightning talk: 12 Factor Containers
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
 
はじめての JFrog Artifactory
はじめての JFrog Artifactoryはじめての JFrog Artifactory
はじめての JFrog Artifactory
 
Everything-as-code: DevOps und Continuous Delivery aus Sicht des Entwicklers.
Everything-as-code: DevOps und Continuous Delivery aus Sicht des Entwicklers.Everything-as-code: DevOps und Continuous Delivery aus Sicht des Entwicklers.
Everything-as-code: DevOps und Continuous Delivery aus Sicht des Entwicklers.
 
Micronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureMicronaut: Changing the Micro Future
Micronaut: Changing the Micro Future
 
Apache Deep Learning 101 - ApacheCon Montreal 2018 v0.31
Apache Deep Learning 101 - ApacheCon Montreal 2018 v0.31Apache Deep Learning 101 - ApacheCon Montreal 2018 v0.31
Apache Deep Learning 101 - ApacheCon Montreal 2018 v0.31
 

Ähnlich wie Raising ux bar with offline first design

Ähnlich wie Raising ux bar with offline first design (20)

Thinking DevOps in the era of the Cloud - Demi Ben-Ari
Thinking DevOps in the era of the Cloud - Demi Ben-AriThinking DevOps in the era of the Cloud - Demi Ben-Ari
Thinking DevOps in the era of the Cloud - Demi Ben-Ari
 
WebSphere Technical University: Introduction to the Java Diagnostic Tools
WebSphere Technical University: Introduction to the Java Diagnostic ToolsWebSphere Technical University: Introduction to the Java Diagnostic Tools
WebSphere Technical University: Introduction to the Java Diagnostic Tools
 
Creating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at ScaleCreating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at Scale
 
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...
 
Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...
Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...
Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...
 
Containers explained as for cook and a mecanics
 Containers explained as for cook and a mecanics  Containers explained as for cook and a mecanics
Containers explained as for cook and a mecanics
 
Angular (v2 and up) - Morning to understand - Linagora
Angular (v2 and up) - Morning to understand - LinagoraAngular (v2 and up) - Morning to understand - Linagora
Angular (v2 and up) - Morning to understand - Linagora
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontend
 
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Berlin 2017
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Berlin 2017Monitoring Big Data Systems Done "The Simple Way" - Codemotion Berlin 2017
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Berlin 2017
 
Where should I run my code? Serverless, Containers, Virtual Machines and more
Where should I run my code? Serverless, Containers, Virtual Machines and moreWhere should I run my code? Serverless, Containers, Virtual Machines and more
Where should I run my code? Serverless, Containers, Virtual Machines and more
 
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
 
Demi Ben-Ari - Monitoring Big Data Systems Done "The Simple Way" - Codemotion...
Demi Ben-Ari - Monitoring Big Data Systems Done "The Simple Way" - Codemotion...Demi Ben-Ari - Monitoring Big Data Systems Done "The Simple Way" - Codemotion...
Demi Ben-Ari - Monitoring Big Data Systems Done "The Simple Way" - Codemotion...
 
Node.js Course 2 of 2 - Advanced techniques
Node.js Course 2 of 2 - Advanced techniquesNode.js Course 2 of 2 - Advanced techniques
Node.js Course 2 of 2 - Advanced techniques
 
Pluggable Infrastructure with CI/CD and Docker
Pluggable Infrastructure with CI/CD and DockerPluggable Infrastructure with CI/CD and Docker
Pluggable Infrastructure with CI/CD and Docker
 
On component interface
On component interfaceOn component interface
On component interface
 
Open source: Top issues in the top enterprise packages
Open source: Top issues in the top enterprise packagesOpen source: Top issues in the top enterprise packages
Open source: Top issues in the top enterprise packages
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
OWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA TestersOWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA Testers
 
Cognos Performance Tuning Tips & Tricks
Cognos Performance Tuning Tips & TricksCognos Performance Tuning Tips & Tricks
Cognos Performance Tuning Tips & Tricks
 

Kürzlich hochgeladen

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Kürzlich hochgeladen (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Raising ux bar with offline first design

  • 1. 1 November 13, 2017 Raising UX bar with Offline- First Design Kyrylo Reznykov
  • 2. 2 Agenda ● Why Do We Need Offline-First Design? ● Browser APIs Essential For Reliable Web Apps. ● The Most Common UI/UX Patterns. ● Offline Storage With Replication to a Server. ● Challenges when you build Offline-First Apps.
  • 3. 3 Why Do We Need Offline-First Design?
  • 4. 4 What is common in two places? Subway, New York Celentano Pizza, Lviv
  • 5. 5 Both places don’t have network coverage
  • 6. 6 The are a lot of situations without connection
  • 7. 7 Also internet is extremely slow in some places Today, 60% of mobile internet users have only 2g connection speeds.
  • 8. 8 UX when your apps don’t care about offline Saving
  • 9. 9 Users see web as unstable platform
  • 10. 10 Data shows that they prefer mobile apps
  • 11. 11 Web has evolved and ready to compete with native apps Pros (compare to native apps): ● No installation. ● It may take less space. ● Web apps are way more secure
  • 12. 12 Web has evolved and ready to compete with native apps Pros (compare to native apps): ● No installation. ● It may take less space. ● Web apps are way more secure Cons: ● Lower performance ● Less APIs available.
  • 13. 13 Browser APIs Essential For Reliable Web Apps.
  • 14. 14 HTML5 Application Cache Pros: Extremely easy to use. Older browsers support it, only option in IE 10 & IE 11. Cons: Can be served over insecure HTTP. Lacks flexibility. Will be removed soon in new browsers. <html manifest="cache.mf"> ... CACHE MANIFEST style.css image.png # Use from network if available NETWORK: list.json FALLBACK: example/bar/ example.html
  • 15. 15 Service Worker API Service worker can handle events even when browser is closed! Browser
  • 16. 16 Service Worker API Support In 2018 every major browser will support SW.
  • 17. 17 Service Worker Lifecycle Register: navigator.serviceWorker.register('/sw.js') // path is a scope .then(reg => console.log('SW registered!', reg)); !! Serve sw.js with Cache-Control: max-age=0
  • 18. 18 Service Worker Lifecycle Register: navigator.serviceWorker.register('/sw.js') // path is a scope .then(reg => console.log('SW registered!', reg)); !! Serve sw.js with Cache-Control: max-age=0
  • 19. 19 Service Worker Lifecycle Register: navigator.serviceWorker.register('/sw.js') // path is a scope .then(reg => console.log('SW registered!', reg)); !! Serve sw.js with Cache-Control: max-age=0
  • 20. 20 Service Worker Install Event const cacheCriticals = () => { return caches.open(CACHE_NAME).then(cache => { // important, but not critical cache.addAll(resourcesToCache); // critical resources return cache.addAll(criticalResources); }); }; self.addEventListener('install', function (installEvent) { installEvent.waitUntil(cacheCriticals()); });
  • 21. 21 Service Worker Activate Event function cleanup(cacheNames) { return Promise.all( cacheNames.filter(function (cacheName) { return cacheName !== CACHE_NAME; }).map(function (cacheName) { return caches.delete(cacheName); }) ); } self.addEventListener('activate', function(event) { event.waitUntil(caches.keys().then(cleanup)); }); *Old service worker is paused at that moment. Fetch requests will be added to queue..
  • 22. 22 Service Worker Fetch Event self.addEventListener('fetch', function(event) { // magic goes here }); *The request is attended by the most specific SW only.
  • 23. 23 Service Worker Fetch Event self.addEventListener('fetch', function(event) { event.respondWith(fetch(event.request)); }); *The request is attended by the most specific SW only.
  • 24. 24 const getCachedOrFetch = function (event) { return caches.match(event.request) .then(response => response || fetch(event.request)); } self.addEventListener('fetch', function(event) { event.respondWith(getCachedOrFetch(event)); }); Service Worker Fetch Event
  • 26. 26 Workbox Offline Caching: ● Cache only ● Cache first, falling back to network ● Cache, with network update ● Network only ● Network first, falling back to cache Offline Analytics: Workbox can collect user analytics while offline.
  • 28. 28 Workbox You can integrate it with: Or use it directly in the service worker: //synchronously imports scripts into the worker's scope importScripts('/node_modules/workbox-sw/build/workbox-sw.vX.X.X.prod.js'); const workboxSW = new WorkboxSW(); const networkFirst = workboxSW.strategies.networkFirst(); workboxSW.router.registerRoute('/schedule', networkFirst);
  • 29. 29 BackgroundSync DEMO Service Worker Background Sync // sync will fire when the user agent believes the user has connectivity self.addEventListener('sync', function(event) { if (event.tag === ‘anyTag’) event.waitUntil(doWhatYouWant()); }); Finally, we have a better option than WindowEventHandlers.onbeforeunload
  • 30. 30 Browser Storage APIs Cache API (part of Service Worker). - use it for URL addressable resources.
  • 31. 31 Browser Storage APIs Cache API (part of Service Worker). - use it for URL addressable resources. IndexedDB - use it for all other data. (Also, exist polyfills with fallback to Web SQL).
  • 32. 32 Browser Storage APIs Cache API (part of Service Worker). - use it for URL addressable resources. IndexedDB - use it for all other data. (Also, exist polyfills with fallback to Web SQL). LocalStorage - Has no Web Worker. But it is persistent storage by default!
  • 33. 33 Browser Storage APIs Cache API (part of Service Worker). - use it for URL addressable resources. IndexedDB - use it for all other data. (Also, exist polyfills with fallback to Web SQL). LocalStorage - Has no Web Worker. But it is persistent storage by default! Space available to origin is shared between all forms of storage above. There is no standard way to check quota. We have two experimental APIs: Quota Management API and Storage Manager API.
  • 34. 34 How much can I store?
  • 35. 35 Be Aware of Cache Eviction in Browsers *If app is not installed by user (Chrome, FF) or don’t have high engagement. Chrome LRU once Chrome runs out of space Firefox LRU if the whole disk gets full Safari & Edge No cache eviction !! It includes Indexed DB and Cache API.
  • 36. 36 Be Aware of Cache Eviction in Browsers *If app is not installed by user (Chrome, FF) or don’t have high engagement. Chrome LRU once Chrome runs out of space Firefox LRU if the whole disk gets full Safari & Edge No cache eviction !! It includes Indexed DB, Cache API. navigator.storage.persist().then(function(isPersistent) { // isPersistent will be true if user allowed })
  • 38. 38 ● Try to provide offline by default if your app doesn't require much data. ● Treat a connection to the internet as an enhancement instead of a dependency ● Use optimistic UI approach if possible. ● User must be properly notified about app state. ● Use save for offline button ● Precache things that needed with high probability offline especially if they are small Core ideas
  • 39. 39 Connection is enhancement not a dependency You can create new google doc while you offline. Once we connect to internet it will be synced.
  • 40. 40 Use optimistic ui approach if possible avoid that approach if possible If we offline, sync that action later.
  • 41. 41 User must be properly notified about app state
  • 42. 42 Use save for offline button Especially important approach for content oriented applications like: ● Spotify ● Google maps ● Web readers ● e.t.c
  • 43. 43 Cache things automatically ● Do you users often use that feature? ● Can it be useful offline? ● Is it lightweight? ● Is it not sensitive data? If answer yes for all Pre-cache it without asking.
  • 45. 45 We are writing distributed system
  • 46. 46 The CAP Theorem You can have at most two of these properties for any shared-data system
  • 47. 47 Offline-First apps needs AP to work We need to sacrifice strong consistency between nodes in favour of high availability of data
  • 48. 48 Already we have a lot of different solutions for that
  • 49. 49 PouchDB + CouchDB CouchDB is was designed from the bottom-up to enable easy synchronization between databases. { "_id": "any_string", "_rev": "1-bea5fa18e06522d12026f4aee6b15ee4" "name": "John", ... }
  • 50. 50 PouchDB + CouchDB Pros: ● Production ready. Well tested ● Nice documentation. ● Wide browser support. Cons ● You are tight to a specific DB which supports its sync protocol on backend. ● Poor automatic conflict resolution* ● Not good for real time apps. *The winner is the version with the longest revision history And in case of a tie, the winner is the revision with the lexicographically highest revision ID; e.g. "12-F4B2..." beats "12-42AA..."
  • 51. 51 Face of average user if you ask him to resolve conflicts
  • 52. 52 Would be nice to have automated resolver
  • 53. 53 Would be nice to have automated resolver
  • 54. 54 CRDT to the rescue
  • 56. 56 Example, why CRDT works Bob John
  • 57. 57 Example, why CRDT works Bob John
  • 58. 58 More about CRDT Well known CRDTs ● G-Counter (Grow-only Counter) ● PN-Counter (Positive-Negative Counter) ● G-Set (Grow-only Set, which only allows adding) ● 2P-Set (Two-Phase Set, remove-wins" set) ● LWW-Element-Set (Last-Write-Wins-Element-Set) ● e.t.c CRDT provides strong eventual consistency (SEC) It means that if all nodes get all updates in whatever order they will come to the same state. If you use inappropriate type you may get messy state, although it will be consistent across app.
  • 59. 59 CRDT is not a silver bullet Cannot model every data type..
  • 60. 60 Swarm.js Pros ● Real time replication ● Automatic conflict resolution ● Need little data to transfer (CmRDT) Cons ● It is kind of research project ● Almost no documentation ● Vague future
  • 61. 61 Logux Pros ● In active development ● Very flexible ● Redux API ● Foundation for CRDT Cons ● Very young project Library inspired by Redux and Swarm.js
  • 62. 62 Gun.js Pros ● In active development ● With real time in mind ● Looks like best open source solution ● Integrates with different Backend DBs Cons ● Not mature enough
  • 63. 63 Challenges when you build Offline- First Apps.
  • 64. 64 - Some useful API still not standardized - Find security/convenience ballance. - Handling multiple users on one machine. - Educate through UI users about what is working offline - Wise Caching. (Do not force user to download whole site on first visit.) - Mobile traffic costs a lot in some places. - Data synchronization tools is quite immature. - New auto testing challenges (Panic Server) Challenges when you build Offline-First Apps
  • 66. 66 More to read - Repository with with information related to offline-first apps - Problems of AppCache - About Service Workers - Is Service Worker Ready - Read more about Workbox - Good Article About Optimistic UI - Complete Gun.js tutorial - Read blog of Swarm.js developer - More About Logux: YouTube Video - CRDT original paperwork - Security thoughts about offline apps - Unit-testing-service-worker - Background Sync - My Offline-First App (Slightly Unfinished)
  • 67. 67 Thank you for your attention