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
68
Você (provavelmente) não sabia que o Chrome DevTools tinha isso
joselito
0
48
Eleventy: Sites em 3 minutos ou seu dinheiro de volta
joselito
0
24
Dando rollback no site do governo
joselito
0
220
Chrome Dev Summit'18
joselito
0
54
Next.js: o desenvolvedor feliz de novo
joselito
0
120
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
240
Other Decks in Programming
See All in Programming
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
250
単体テストを書かない技術 #phpcon_odawara
o0h
PRO
26
7.9k
HUIT新歓2024「競技プログラミング、やってみませんか?」
slephy2784
1
250
What We Can Learn From OSS
inouehi
0
400
try! Swift Tokyo 初参加報告LT
hinakko2
0
190
品質とスピードを両立: TypeScriptの柔軟な型システムをバックエンドで活用する
kosui
8
2.2k
今の SmartHR にエンジニアで入社するとどうなるの?
daisukeshinoku
5
4.6k
Ruby Pattern Matching
bkuhlmann
0
920
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
39
18k
雑に思考を整理する技術と効能
konifar
55
26k
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
120
Front-end application development, Symfony-style(s)
dunglas
2
1.9k
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
273
13k
Adopting Sorbet at Scale
ufuk
67
8.6k
BBQ
matthewcrist
80
8.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
13
1.5k
Faster Mobile Websites
deanohume
297
30k
What's in a price? How to price your products and services
michaelherold
237
11k
Creatively Recalculating Your Daily Design Routine
revolveconf
209
11k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
The Cost Of JavaScript in 2023
addyosmani
14
3.8k
Clear Off the Table
cherdarchuk
83
310k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
154
14k
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