Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
WebApps Offline com ServiceWorkers
Search
joseli.to
January 13, 2016
Programming
2
170
WebApps Offline com ServiceWorkers
Hangout - GDG BH
joseli.to
January 13, 2016
Tweet
Share
More Decks by joseli.to
See All by joseli.to
Virei Lead, como me manter Tech enquanto gerencio pessoas?
joselito
0
94
Você (provavelmente) não sabia que o Chrome DevTools tinha isso
joselito
0
63
Eleventy: Sites em 3 minutos ou seu dinheiro de volta
joselito
0
34
Dando rollback no site do governo
joselito
0
230
Chrome Dev Summit'18
joselito
0
59
Next.js: o desenvolvedor feliz de novo
joselito
0
140
Componentizando a Web
joselito
0
150
Firebase para se divertir com IoT
joselito
0
140
Conectando com o mundo real: Physical Web e Web Bluetooth
joselito
1
250
Other Decks in Programming
See All in Programming
個人開発で使ってるやつを紹介する回
yohfee
1
660
Cancel Next.js Page Navigation: Full Throttle
ypresto
1
110
Assembling the Future: crafting the missing pieces of the Ruby on Wasm puzzle
skryukov
0
130
Compose Multiplatform과 Ktor로 플랫폼의 경계를 넘어보자
kwakeuijin
0
230
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
6
230
Quarto Clean Theme
nicetak
0
220
為醫療加裝Python的引擎
cclai999
0
270
Cohesion in Modeling and Design
mploed
3
180
WEBアプリケーションにおけるAWS Lambdaを用いた大規模な非同期処理の実践
delhi09
PRO
7
3.8k
コードレビューと私の過去と未来
jxmtst
0
180
sqlcを利用してsqlに型付けを
kamiyam
0
230
Applied NLP in the Age of Generative AI
inesmontani
PRO
3
1.1k
Featured
See All Featured
Scaling GitHub
holman
458
140k
Fashionably flexible responsive web design (full day workshop)
malarkey
403
65k
The Cult of Friendly URLs
andyhume
76
6k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
2
220
WebSockets: Embracing the real-time Web
robhawkes
59
7.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
1
240
Designing for humans not robots
tammielis
249
25k
Designing with Data
zakiwarfel
98
5.1k
Adopting Sorbet at Scale
ufuk
73
8.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
653
59k
BBQ
matthewcrist
84
9.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
230
17k
Transcript
JOSELITO.NINJA WEB APPS OFFLINE Hangout - GDG Belo Horizonte
@joselitojunior1
MOBILE @joselitojunior1
NATIVO v WEB @joselitojunior1
NATIVO v WEB @joselitojunior1
@joselitojunior1
@joselitojunior1 PROGRESIVE APPS
@joselitojunior1 PROGRESIVE APPS offline first responsive fresh content https safe
indexable installable linkable engageble
@joselitojunior1 PROGRESIVE APPS offline first responsive fresh content https safe
indexable installable linkable engageble
Olá, Joselito • Modelo e atriz • Instrutor, palestrante •
Ex-BBB • GDG Organizer • Fã de F1 • Resolvedor® de problemas • #chrominho
@joselitojunior1 OFFLINE APPS
@joselitojunior1 hIps://speakerdeck.com/joselitojunior1
@joselitojunior1 OFFLINE === USER EXPERIENCE
SERVICE WORKERS @joselitojunior1
@joselitojunior1
SERVICE WORKERS @joselitojunior1 Registro do SW no navegador
@joselitojunior1 if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/ssw.js', { scope: '/'
}).then(function(reg) { // Service Worker registrado! }).catch(function(error) { // Não foi possível registrar o Service Worker console.log(error); }); };
@joselitojunior1 this.addEventListener('install', function(event) { event.waitUntil( caches.open('cache-versao-1').then(function(cache) { return cache.addAll([ '/public/',
'/public/index.html', '/public/estilo.css', '/public/app.js', '/public/image-list.js', '/public/info.json' ]); }) ); });
@joselitojunior1 this.addEventListener('fetch', function(event) { event.respondWith( // Mágica! ); });
@joselitojunior1 this.addEventListener('fetch', function(event) { event.respondWith( // Response() ); });
SERVICE WORKERS @joselitojunior1 Response()
@joselitojunior1 new Response('Hello from GDG Humildão');
@joselitojunior1 new Response('<p>Hello from GDG Humildão!</p>', { headers: { 'Content-Type':
'text/html' } })
@joselitojunior1 fetch(event.request)
@joselitojunior1 caches.match('/fallback.html');
@joselitojunior1 caches.match('/fallback.html');
SERVICE WORKERS @joselitojunior1 onfetch()
@joselitojunior1 self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request).then(function(response) { return response ||
fetch(event.request); }) ); });
@joselitojunior1 self.addEventListener('fetch', function(event) { event.respondWith( caches.open('mysite-dynamic').then(function(cache) { return cache.match(event.request).then(function (response)
{ return response || fetch(event.request).then(function(response) { cache.put(event.request, response.clone()); return response; }); }); }) ); });
@joselitojunior1 self.addEventListener('fetch', function(event) { event.respondWith( caches.open('mysite-dynamic').then(function(cache) { return cache.match(event.request).then(function(response) {
var fetchPromise = fetch(event.request).then(function(networkResponse) { cache.put(event.request, networkResponse.clone()); return networkResponse; }) return response || fetchPromise; }) }) ); });
SERVICE WORKERS @joselitojunior1 onsync()
@joselitojunior1 self.addEventListener('sync', function(event) { if (event.id == 'update-leaderboard') { event.waitUntil(
caches.open('mygame-dynamic').then(function(cache) { return cache.add('/leaderboard.json'); }) ); } });
SERVICE WORKERS @joselitojunior1 onactivate()
@joselitojunior1 self.addEventListener('activate', function(event) { // Service Worker funcionando! });
@joselitojunior1 self.onactivate = function(event) { event.waitUntil( caches.keys().then(function(cacheNames) { return Promise.all(
cacheNames.map(function(cacheName) { if (expectedCaches.indexOf(cacheName) == -1) { return caches.delete(cacheName); } }) ); }) ); };
SERVICE WORKERS @joselitojunior1 Debugando
@joselitojunior1
SERVICE WORKERS @joselitojunior1 Exemplos
@joselitojunior1 Wikipedia OTine github.com/jakearchibald/oTine-wikipedia
@joselitojunior1 DevFest Nordeste github.com/devfestne/2015-site
Obrigado (: JOSELITO.NINJA @joselitojunior1