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
Joselito
January 13, 2016
Programming
2
190
WebApps Offline com ServiceWorkers
Hangout - GDG BH
Joselito
January 13, 2016
Tweet
Share
More Decks by Joselito
See All by Joselito
Apresentando window.ai
joselito
0
43
Virei Lead, como me manter Tech enquanto gerencio pessoas?
joselito
0
130
Você (provavelmente) não sabia que o Chrome DevTools tinha isso
joselito
1
80
Eleventy: Sites em 3 minutos ou seu dinheiro de volta
joselito
0
48
Dando rollback no site do governo
joselito
0
250
Chrome Dev Summit'18
joselito
0
67
Next.js: o desenvolvedor feliz de novo
joselito
0
150
Componentizando a Web
joselito
0
170
Firebase para se divertir com IoT
joselito
0
160
Other Decks in Programming
See All in Programming
【第4回】関東Kaggler会「Kaggleは執筆に役立つ」
mipypf
0
1k
RDoc meets YARD
okuramasafumi
4
160
rage against annotate_predecessor
junk0612
0
150
複雑なドメインに挑む.pdf
yukisakai1225
5
910
Claude Codeで実装以外の開発フロー、どこまで自動化できるか?失敗と成功
ndadayo
4
1.8k
機能追加とリーダー業務の類似性
rinchoku
0
360
FindyにおけるTakumi活用と脆弱性管理のこれから
rvirus0817
0
370
MCPでVibe Working。そして、結局はContext Eng(略)/ Working with Vibe on MCP And Context Eng
rkaga
5
1.2k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
300
パスタの技術
yusukebe
1
560
testingを眺める
matumoto
1
130
開発チーム・開発組織の設計改善スキルの向上
masuda220
PRO
18
9.6k
Featured
See All Featured
Producing Creativity
orderedlist
PRO
347
40k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
KATA
mclloyd
32
14k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.8k
Unsuck your backbone
ammeep
671
58k
Become a Pro
speakerdeck
PRO
29
5.5k
A better future with KSS
kneath
239
17k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
9
800
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.5k
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