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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Joselito
January 13, 2016
Programming
220
2
Share
WebApps Offline com ServiceWorkers
Hangout - GDG BH
Joselito
January 13, 2016
More Decks by Joselito
See All by Joselito
Apresentando window.ai
joselito
0
66
Virei Lead, como me manter Tech enquanto gerencio pessoas?
joselito
0
150
Você (provavelmente) não sabia que o Chrome DevTools tinha isso
joselito
1
91
Eleventy: Sites em 3 minutos ou seu dinheiro de volta
joselito
0
62
Dando rollback no site do governo
joselito
0
260
Chrome Dev Summit'18
joselito
0
87
Next.js: o desenvolvedor feliz de novo
joselito
0
170
Componentizando a Web
joselito
0
180
Firebase para se divertir com IoT
joselito
0
170
Other Decks in Programming
See All in Programming
[RubyKaigi 2026] Require Hooks
palkan
1
270
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
180
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
460
エラー処理の温故知新 / history of error handling technic
ryotanakaya
7
1.8k
PHPでローカル環境用のSSL/TLS証明書を発行することはできるのか? #phpconkagawa
akase244
0
270
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
「話せることがない」を乗り越える 〜日常業務から登壇テーマをつくる思考法〜
shoheimitani
4
940
Don't Prompt Harder, Structure Better
kitasuke
0
800
mruby on C#: From VM Implementation to Game Scripting (RubyKaigi 2026)
hadashia
2
1.4k
Kingdom of the Machine
yui_knk
2
1.3k
GoogleCloudとterraform完全に理解した
terisuke
1
180
個人的に嬉しかったpnpmの新機能・3選
matsuo_atsushi
0
120
Featured
See All Featured
ラッコキーワード サービス紹介資料
rakko
1
3.2M
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
180
YesSQL, Process and Tooling at Scale
rocio
174
15k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Un-Boring Meetings
codingconduct
0
280
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
KATA
mclloyd
PRO
35
15k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
64
54k
Speed Design
sergeychernyshev
33
1.6k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.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