2. @bmihaylov | BuildStuff 2016 2
We live in a connected world
https://c1app.wordpress.com/2015/02/02/mobile-apps-a-simple-overview/social-media-network-connection-and-communication-in-the-global_z1j0gjo_/
4. Working while travelling
@bmihaylov | BuildStuff 2016 4
https://www.wired.com/wp-content/uploads/blogs/wiredenterprise/wp-content/uploads/2013/09/docker-jungle.jpg
26. FileSystem API
@bmihaylov | BuildStuff 2016 26
+ A sandboxed file system
+ Store binary content
– May ask for extra quota
– Only supported in Chrome
– Non-standard
window.webkitStorageInfo
.requestQuota(PERSISTENT, 1024*1024, (quota) => {
window.requestFileSystem(PERSISTENT, quota, onInit, onError);
}, onError);
function onInit(fs) {
fs.root.getFile(
"log.txt", { create: true, exclusive: true },
(fileEntry) => { /* fileEntry.name */ },
onError);
}
27. Service Worker
A script running in the background
Even when the browser is closed
Acts as a proxy between the browser and
the network (when available)
Programmatic and controllable
Cache API
27@bmihaylov | BuildStuff 2016
29. Service Worker – register
@bmihaylov | BuildStuff 2016 29
<script>
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("app-install.js")
.then(function() {
console.log("Service worker has been installed");
}, function(error) {
console.log("Oops!", error);
});
} else {
console.log("No service workers support for this browser");
}
</script>
32. Service Worker specifics
HTTPs only
Asynchronous, promise-based
Not working with localStorage
indexedDB only
No access to DOM
Isn’t tied to a particular page
32@bmihaylov | BuildStuff 2016
35. Cache only
@bmihaylov | BuildStuff 2016 35
www.
1 2
3
Scenarios
• The static part of your app
36. Cache, falling back to network
@bmihaylov | BuildStuff 2016 36
www.
1
2
3
4
Scenarios
• The majority of requests
when building offline-first
app
37. Network, falling back to cache
@bmihaylov | BuildStuff 2016 37
www.
1
3
2
4
Scenarios
• Online users will always
get the latest content
• Offline users will get older
content
38. Cache & update
@bmihaylov | BuildStuff 2016 38
www.
1
2
2
3
4
Scenarios
• You don’t mind showing
old content for a while
39. Cache, update, refresh
@bmihaylov | BuildStuff 2016 39
www.
1
2
2
3
4
4
Scenarios
• Content that changes often
(fx., game score, social
media timeline)
40. Network & cache race
@bmihaylov | BuildStuff 2016 40
www.
1
2
2
3
3
Scenarios
• Small “non-important”
assets
• Where performance
is vital