SlideShare a Scribd company logo
1 of 54
Download to read offline
PWA
& Service Worker Anna Su
1
Anna Su
PIXNET
2
About me
Why PWA?
What's PWA?
What's Service Workers
Making A Service Worker
3
Agenda
PWA
4
Why
5
What’s Wrong?
What’s Wrong with
Web ?
Slow mobile network
User-unfriendly
6
What’s Wrong with
Web ?
Slow mobile network
7
53% 3s
What’s Wrong with
Web ?
User-unfriendly
8
Splash Screen push notifications
What’s Wrong with
App ?
High cost
Difficultly share
9
What’s Wrong with
App ?
High cost
10
iOS WindowsAndroid
What’s Wrong with
App ?
Difficultly share
11
from Alex Russell in Chrome Dev Summit 2015
1
month
25 100+
App Web
What’s Wrong with
App ?
12
Alex Russell in Chrome Dev Summit 2015 ignite online & comScore
13
PWA
14
What’s
Progressive Web App
15
Reliable Fast EngagingReliable
What’s PWA ?
Reliable
16
What’s PWA ?
Fast
17
What’s PWA ?
Engaging
18
Chrome Dev Summit 2014
[github]
How does the PWA
looks like
19
20
Service Workers
21
What’s
22
What’s Service Workers ?
What’s Service Workers ?
23
24
What’s Service Workers ?
Service Workers
Lifecycle
25
Making
A
Service Worker
26
27
Making A Service Workers
design @Don
simple-pwa-demo
PWA To-Do List with Vanilla JS
(sw-precache)
(sw-precache-webpack-plugin)
PWA To-Do List with React/Redux
28
@Octocat
Making A Service Workers
code review -Jerry Hong
Getting Started with Service Workers
29
Registering the Service Worker
Setting up the Default Cache
Clearing Old Cache
Handling Fetch Requests
30
Making A Service Workers
31
Register install activate fetch
Making A Service Workers
Register
Registering the Service Worker
Registering the Service Worker
32
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('SW registered!', reg))
.catch(err => console.log('Error!', err));
}
</script>
index.html
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('SW registered!', reg))
.catch(err => console.log('Error!', err));
}
</script>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('SW registered!', reg))
.catch(err => console.log('Error!', err));
}
</script>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('SW registered!', reg))
.catch(err => console.log('Error!', err));
}
</script>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('SW registered!', reg))
.catch(err => console.log('Error!', err));
}
</script>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('SW registered!', reg))
.catch(err => console.log('Error!', err));
}
</script>
33
Register install activate fetch
Making A Service Workers
Register
Service Worker Lifecycle
install activate fetch
Getting Started with Service Workers
34
// install
self.addEventListener('install', event => {
console.log('installing…');
});
// activate
self.addEventListener('activate', event => {
console.log('now ready to handle fetches!');
});
// fetch
self.addEventListener('fetch', event => {
console.log('now fetch!');
});
sw.js
35
Register install activate fetch
Setting up the Default Cache
Making A Service Workers
Setting up the Default Cache
36
sw.js
const filesToCache = [
'/',
'/assets/images/btn_check.png',
'/assets/images/btn_del.png',
'/assets/images/ic_add.png',
'/assets/images/logo_todo.png',
'/src/main.css',
'/index.html'
];
const cacheName = 'todolist-v1';
Setting up the Default Cache
37
sw.js
// install
self.addEventListener('install', event => {
console.log('installing…');
event.waitUntil(
caches.open(cacheName).then(cache => {
// console.log('Caching app ok');
return cache.addAll(filesToCache);
})
);
});
// install
self.addEventListener('install', event => {
console.log('installing…');
event.waitUntil(
caches.open(cacheName).then(cache => {
// console.log('Caching app ok');
return cache.addAll(filesToCache);
})
);
});
// install
self.addEventListener('install', event => {
console.log('installing…');
event.waitUntil(
caches.open(cacheName).then(cache => {
// console.log('Caching app ok');
return cache.addAll(filesToCache);
})
);
});
// install
self.addEventListener('install', event => {
console.log('installing…');
event.waitUntil(
caches.open(cacheName).then(cache => {
// console.log('Caching app ok');
return cache.addAll(filesToCache);
})
);
});
// install
self.addEventListener('install', event => {
console.log('installing…');
event.waitUntil(
caches.open(cacheName).then(cache => {
// console.log('Caching app ok');
return cache.addAll(filesToCache);
})
);
});
38
Register install activate fetch
Clearing Old Cache
Making A Service Workers
`
39
// activate
self.addEventListener('activate', event => {
console.log('now ready to handle fetches!');
event.waitUntil(
caches.keys().then(function(cacheNames) {
var promiseArr = cacheNames.map(function(item) {
if (item !== cacheName) {
// Delete that cached file
return caches.delete(item);
}
})
return Promise.all(promiseArr);
})
); // end e.waitUntil
});
sw.js
// activate
self.addEventListener('activate', event => {
console.log('now ready to handle fetches!');
event.waitUntil(
caches.keys().then(function(cacheNames) {
var promiseArr = cacheNames.map(function(item) {
if (item !== cacheName) {
// Delete that cached file
return caches.delete(item);
}
})
return Promise.all(promiseArr);
})
); // end e.waitUntil
});
// activate
self.addEventListener('activate', event => {
console.log('now ready to handle fetches!');
event.waitUntil(
caches.keys().then(function(cacheNames) {
var promiseArr = cacheNames.map(function(item) {
if (item !== cacheName) {
// Delete that cached file
return caches.delete(item);
}
})
return Promise.all(promiseArr);
})
); // end e.waitUntil
});
// activate
self.addEventListener('activate', event => {
console.log('now ready to handle fetches!');
event.waitUntil(
caches.keys().then(function(cacheNames) {
var promiseArr = cacheNames.map(function(item) {
if (item !== cacheName) {
// Delete that cached file
return caches.delete(item);
}
})
return Promise.all(promiseArr);
})
); // end e.waitUntil
});
// activate
self.addEventListener('activate', event => {
console.log('now ready to handle fetches!');
event.waitUntil(
caches.keys().then(function(cacheNames) {
var promiseArr = cacheNames.map(function(item) {
if (item !== cacheName) {
// Delete that cached file
return caches.delete(item);
}
})
return Promise.all(promiseArr);
})
); // end e.waitUntil
});
40
Register install activate fetch
Handling Fetch Requests
Making A Service Workers
41
<script>
const list = document.getElementById('list');
// request
fetch('http://localhost:3000/people')
.then(res => {
return res.json();
})
.then(json => {
list.innerHTML = json
.map(item => `<li>${item.name}</li>`)
.join('');
})
</script>
index.html
Handling Fetch Requests
Handling Fetch Requests
42
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
sw.js
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
43
44
Learn more?
45
46
47
48
49
50
PWA?
PWA?
Service Work
Registering the Service Worker
Setting up the Default Cache
Clearing Old Cache
Handling Fetch Requests
PWA To-Do List -
51
2017 iT
ref
https://huangxuan.me/pwa-qcon2016/#/
https://medium.com/lets-grow-business/why-
progressive-web-app-31dd11d9a925#.zb3d2m1jv
https://igniteonline.com.au/why-progressive-web-
apps-beat-native-apps-hands-down/
52
ref images
http://ninetailsfoxchan.deviantart.com/art/Sad-
Png-by-NFC-304044918
http://mrmen.wikia.com/wiki/File:Mr._All-
Goes_Wrong.PNG
https://goo.gl/022j4n
https://www.labnol.org/software/chrome-offline-
dinosaur-game/28781/
53
Thanks
54

More Related Content

What's hot

Introduction of Progressive Web App
Introduction of Progressive Web AppIntroduction of Progressive Web App
Introduction of Progressive Web AppSankalp Khandelwal
 
Progressive Web Apps / GDG DevFest - Season 2016
Progressive Web Apps / GDG DevFest - Season 2016Progressive Web Apps / GDG DevFest - Season 2016
Progressive Web Apps / GDG DevFest - Season 2016Abdelrahman Omran
 
Why Progressive Web App is what you need for your Business
Why Progressive Web App is what you need for your BusinessWhy Progressive Web App is what you need for your Business
Why Progressive Web App is what you need for your BusinessLets Grow Business
 
Progressive web apps
Progressive web appsProgressive web apps
Progressive web appsAkshay Sharma
 
Service Worker Presentation
Service Worker PresentationService Worker Presentation
Service Worker PresentationKyle Dorman
 
Progressive Web App
Progressive Web AppProgressive Web App
Progressive Web AppSubodh Garg
 
Why Progressive Web Apps For WordPress - WordCamp Finland
Why Progressive Web Apps For WordPress - WordCamp FinlandWhy Progressive Web Apps For WordPress - WordCamp Finland
Why Progressive Web Apps For WordPress - WordCamp FinlandImran Sayed
 
Puppeteer can automate that! - Frontmania
Puppeteer can automate that! - FrontmaniaPuppeteer can automate that! - Frontmania
Puppeteer can automate that! - FrontmaniaÖnder Ceylan
 
NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA  NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA Pramendra Gupta
 
Angular based enterprise level frontend architecture
Angular based enterprise level frontend architectureAngular based enterprise level frontend architecture
Angular based enterprise level frontend architectureHimanshu Tamrakar
 
Microservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring CloudMicroservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring CloudEberhard Wolff
 

What's hot (20)

Progressive Web Apps(PWA)
Progressive Web Apps(PWA)Progressive Web Apps(PWA)
Progressive Web Apps(PWA)
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
 
Introduction of Progressive Web App
Introduction of Progressive Web AppIntroduction of Progressive Web App
Introduction of Progressive Web App
 
Progressive Web-App (PWA)
Progressive Web-App (PWA)Progressive Web-App (PWA)
Progressive Web-App (PWA)
 
Progressive Web Apps / GDG DevFest - Season 2016
Progressive Web Apps / GDG DevFest - Season 2016Progressive Web Apps / GDG DevFest - Season 2016
Progressive Web Apps / GDG DevFest - Season 2016
 
Why Progressive Web App is what you need for your Business
Why Progressive Web App is what you need for your BusinessWhy Progressive Web App is what you need for your Business
Why Progressive Web App is what you need for your Business
 
Progressive web apps
Progressive web appsProgressive web apps
Progressive web apps
 
Pwa.pptx
Pwa.pptxPwa.pptx
Pwa.pptx
 
Spring notes
Spring notesSpring notes
Spring notes
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
 
Service Worker Presentation
Service Worker PresentationService Worker Presentation
Service Worker Presentation
 
Progressive Web App
Progressive Web AppProgressive Web App
Progressive Web App
 
Why Progressive Web Apps For WordPress - WordCamp Finland
Why Progressive Web Apps For WordPress - WordCamp FinlandWhy Progressive Web Apps For WordPress - WordCamp Finland
Why Progressive Web Apps For WordPress - WordCamp Finland
 
Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Webflux
Spring WebfluxSpring Webflux
Spring Webflux
 
Puppeteer can automate that! - Frontmania
Puppeteer can automate that! - FrontmaniaPuppeteer can automate that! - Frontmania
Puppeteer can automate that! - Frontmania
 
NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA  NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA
 
Angular based enterprise level frontend architecture
Angular based enterprise level frontend architectureAngular based enterprise level frontend architecture
Angular based enterprise level frontend architecture
 
Microservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring CloudMicroservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring Cloud
 

Similar to PWA 與 Service Worker

Service Worker - Reliability bits
Service Worker - Reliability bitsService Worker - Reliability bits
Service Worker - Reliability bitsjungkees
 
[1C1]Service Workers
[1C1]Service Workers[1C1]Service Workers
[1C1]Service WorkersNAVER D2
 
Offline First with Service Worker
Offline First with Service WorkerOffline First with Service Worker
Offline First with Service WorkerMuhammad Samu
 
Service workers
Service workersService workers
Service workersjungkees
 
JQuery UK February 2015: Service Workers On Vacay
JQuery UK February 2015: Service Workers On VacayJQuery UK February 2015: Service Workers On Vacay
JQuery UK February 2015: Service Workers On VacayNatasha Rooney
 
JQuery UK Service Workers Talk
JQuery UK Service Workers TalkJQuery UK Service Workers Talk
JQuery UK Service Workers TalkNatasha Rooney
 
Asynchronous Programming at Netflix
Asynchronous Programming at NetflixAsynchronous Programming at Netflix
Asynchronous Programming at NetflixC4Media
 
Service worker - Offline Web
Service worker - Offline WebService worker - Offline Web
Service worker - Offline WebBruno Oliveira
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "FDConf
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!Chang W. Doh
 
Service workers and the role they play in modern day web apps
Service workers and the role they play in modern day web appsService workers and the role they play in modern day web apps
Service workers and the role they play in modern day web appsMukul Jain
 
Introduction to Service Workers | Matteo Manchi
Introduction to Service Workers | Matteo ManchiIntroduction to Service Workers | Matteo Manchi
Introduction to Service Workers | Matteo ManchiCodemotion
 
New improvements for web developers - frontend.fi, Helsinki
New improvements for web developers - frontend.fi, HelsinkiNew improvements for web developers - frontend.fi, Helsinki
New improvements for web developers - frontend.fi, HelsinkiRobert Nyman
 
Building Offline Ready and Installable Web App
Building Offline Ready and Installable Web AppBuilding Offline Ready and Installable Web App
Building Offline Ready and Installable Web AppMuhammad Samu
 
PWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service WorkerPWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service Workerjungkees
 
Building Progressive Web Apps for Windows devices
Building Progressive Web Apps for Windows devicesBuilding Progressive Web Apps for Windows devices
Building Progressive Web Apps for Windows devicesWindows Developer
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Codemotion
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changerSandro Paganotti
 

Similar to PWA 與 Service Worker (20)

Service Worker - Reliability bits
Service Worker - Reliability bitsService Worker - Reliability bits
Service Worker - Reliability bits
 
[1C1]Service Workers
[1C1]Service Workers[1C1]Service Workers
[1C1]Service Workers
 
Offline First with Service Worker
Offline First with Service WorkerOffline First with Service Worker
Offline First with Service Worker
 
Service workers
Service workersService workers
Service workers
 
JQuery UK February 2015: Service Workers On Vacay
JQuery UK February 2015: Service Workers On VacayJQuery UK February 2015: Service Workers On Vacay
JQuery UK February 2015: Service Workers On Vacay
 
JQuery UK Service Workers Talk
JQuery UK Service Workers TalkJQuery UK Service Workers Talk
JQuery UK Service Workers Talk
 
Asynchronous Programming at Netflix
Asynchronous Programming at NetflixAsynchronous Programming at Netflix
Asynchronous Programming at Netflix
 
Service worker - Offline Web
Service worker - Offline WebService worker - Offline Web
Service worker - Offline Web
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!
 
Service workers and the role they play in modern day web apps
Service workers and the role they play in modern day web appsService workers and the role they play in modern day web apps
Service workers and the role they play in modern day web apps
 
Introduction to Service Workers | Matteo Manchi
Introduction to Service Workers | Matteo ManchiIntroduction to Service Workers | Matteo Manchi
Introduction to Service Workers | Matteo Manchi
 
New improvements for web developers - frontend.fi, Helsinki
New improvements for web developers - frontend.fi, HelsinkiNew improvements for web developers - frontend.fi, Helsinki
New improvements for web developers - frontend.fi, Helsinki
 
Building Offline Ready and Installable Web App
Building Offline Ready and Installable Web AppBuilding Offline Ready and Installable Web App
Building Offline Ready and Installable Web App
 
PWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service WorkerPWA Roadshow Korea - Service Worker
PWA Roadshow Korea - Service Worker
 
Building Progressive Web Apps for Windows devices
Building Progressive Web Apps for Windows devicesBuilding Progressive Web Apps for Windows devices
Building Progressive Web Apps for Windows devices
 
You promise?
You promise?You promise?
You promise?
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changer
 
Airflow and supervisor
Airflow and supervisorAirflow and supervisor
Airflow and supervisor
 

More from Anna Su

Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureAnna Su
 
2017 台灣成長駭客年會 與會心得分享
2017 台灣成長駭客年會 與會心得分享2017 台灣成長駭客年會 與會心得分享
2017 台灣成長駭客年會 與會心得分享Anna Su
 
PWA 應用與價值
PWA 應用與價值PWA 應用與價值
PWA 應用與價值Anna Su
 
初探 DevOps 的世界
初探 DevOps 的世界初探 DevOps 的世界
初探 DevOps 的世界Anna Su
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?Anna Su
 
NASA hackathon - Sea More
NASA hackathon - Sea MoreNASA hackathon - Sea More
NASA hackathon - Sea MoreAnna Su
 
用 Javascript 實現你的想像
用 Javascript 實現你的想像用 Javascript 實現你的想像
用 Javascript 實現你的想像Anna Su
 
PWA 應用 - 實現網站離線瀏覽
PWA 應用 - 實現網站離線瀏覽PWA 應用 - 實現網站離線瀏覽
PWA 應用 - 實現網站離線瀏覽Anna Su
 
網站建置流程
網站建置流程網站建置流程
網站建置流程Anna Su
 
網站建置初探
網站建置初探網站建置初探
網站建置初探Anna Su
 
2016 PIXNET HACKATHON Lightning talk - 做網站不是只有一個人的事
2016 PIXNET HACKATHON Lightning talk - 做網站不是只有一個人的事2016 PIXNET HACKATHON Lightning talk - 做網站不是只有一個人的事
2016 PIXNET HACKATHON Lightning talk - 做網站不是只有一個人的事Anna Su
 
從一個超簡單範例開始學習 Canvas
從一個超簡單範例開始學習 Canvas從一個超簡單範例開始學習 Canvas
從一個超簡單範例開始學習 CanvasAnna Su
 
Rucksack 裝滿神奇 css 的後背包
Rucksack 裝滿神奇 css 的後背包Rucksack 裝滿神奇 css 的後背包
Rucksack 裝滿神奇 css 的後背包Anna Su
 
CSS modules 簡單玩
CSS modules 簡單玩CSS modules 簡單玩
CSS modules 簡單玩Anna Su
 
Trello - 規劃工作與生活的管理工具
Trello - 規劃工作與生活的管理工具Trello - 規劃工作與生活的管理工具
Trello - 規劃工作與生活的管理工具Anna Su
 
webpack 入門
webpack 入門webpack 入門
webpack 入門Anna Su
 
入門Gulp - 前端自動化開發工具
入門Gulp - 前端自動化開發工具入門Gulp - 前端自動化開發工具
入門Gulp - 前端自動化開發工具Anna Su
 
幸福快樂的完美結局
幸福快樂的完美結局幸福快樂的完美結局
幸福快樂的完美結局Anna Su
 
偷呷步的網站快速入門
偷呷步的網站快速入門偷呷步的網站快速入門
偷呷步的網站快速入門Anna Su
 
調配網站的明星花露水
調配網站的明星花露水調配網站的明星花露水
調配網站的明星花露水Anna Su
 

More from Anna Su (20)

Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
2017 台灣成長駭客年會 與會心得分享
2017 台灣成長駭客年會 與會心得分享2017 台灣成長駭客年會 與會心得分享
2017 台灣成長駭客年會 與會心得分享
 
PWA 應用與價值
PWA 應用與價值PWA 應用與價值
PWA 應用與價值
 
初探 DevOps 的世界
初探 DevOps 的世界初探 DevOps 的世界
初探 DevOps 的世界
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?
 
NASA hackathon - Sea More
NASA hackathon - Sea MoreNASA hackathon - Sea More
NASA hackathon - Sea More
 
用 Javascript 實現你的想像
用 Javascript 實現你的想像用 Javascript 實現你的想像
用 Javascript 實現你的想像
 
PWA 應用 - 實現網站離線瀏覽
PWA 應用 - 實現網站離線瀏覽PWA 應用 - 實現網站離線瀏覽
PWA 應用 - 實現網站離線瀏覽
 
網站建置流程
網站建置流程網站建置流程
網站建置流程
 
網站建置初探
網站建置初探網站建置初探
網站建置初探
 
2016 PIXNET HACKATHON Lightning talk - 做網站不是只有一個人的事
2016 PIXNET HACKATHON Lightning talk - 做網站不是只有一個人的事2016 PIXNET HACKATHON Lightning talk - 做網站不是只有一個人的事
2016 PIXNET HACKATHON Lightning talk - 做網站不是只有一個人的事
 
從一個超簡單範例開始學習 Canvas
從一個超簡單範例開始學習 Canvas從一個超簡單範例開始學習 Canvas
從一個超簡單範例開始學習 Canvas
 
Rucksack 裝滿神奇 css 的後背包
Rucksack 裝滿神奇 css 的後背包Rucksack 裝滿神奇 css 的後背包
Rucksack 裝滿神奇 css 的後背包
 
CSS modules 簡單玩
CSS modules 簡單玩CSS modules 簡單玩
CSS modules 簡單玩
 
Trello - 規劃工作與生活的管理工具
Trello - 規劃工作與生活的管理工具Trello - 規劃工作與生活的管理工具
Trello - 規劃工作與生活的管理工具
 
webpack 入門
webpack 入門webpack 入門
webpack 入門
 
入門Gulp - 前端自動化開發工具
入門Gulp - 前端自動化開發工具入門Gulp - 前端自動化開發工具
入門Gulp - 前端自動化開發工具
 
幸福快樂的完美結局
幸福快樂的完美結局幸福快樂的完美結局
幸福快樂的完美結局
 
偷呷步的網站快速入門
偷呷步的網站快速入門偷呷步的網站快速入門
偷呷步的網站快速入門
 
調配網站的明星花露水
調配網站的明星花露水調配網站的明星花露水
調配網站的明星花露水
 

Recently uploaded

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

PWA 與 Service Worker

  • 3. Why PWA? What's PWA? What's Service Workers Making A Service Worker 3 Agenda
  • 6. What’s Wrong with Web ? Slow mobile network User-unfriendly 6
  • 7. What’s Wrong with Web ? Slow mobile network 7 53% 3s
  • 8. What’s Wrong with Web ? User-unfriendly 8 Splash Screen push notifications
  • 9. What’s Wrong with App ? High cost Difficultly share 9
  • 10. What’s Wrong with App ? High cost 10 iOS WindowsAndroid
  • 11. What’s Wrong with App ? Difficultly share 11 from Alex Russell in Chrome Dev Summit 2015 1 month 25 100+ App Web
  • 12. What’s Wrong with App ? 12 Alex Russell in Chrome Dev Summit 2015 ignite online & comScore
  • 13. 13
  • 19. Chrome Dev Summit 2014 [github] How does the PWA looks like 19
  • 20. 20
  • 27. 27 Making A Service Workers design @Don
  • 28. simple-pwa-demo PWA To-Do List with Vanilla JS (sw-precache) (sw-precache-webpack-plugin) PWA To-Do List with React/Redux 28 @Octocat Making A Service Workers code review -Jerry Hong
  • 29. Getting Started with Service Workers 29
  • 30. Registering the Service Worker Setting up the Default Cache Clearing Old Cache Handling Fetch Requests 30 Making A Service Workers
  • 31. 31 Register install activate fetch Making A Service Workers Register Registering the Service Worker
  • 32. Registering the Service Worker 32 <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js') .then(reg => console.log('SW registered!', reg)) .catch(err => console.log('Error!', err)); } </script> index.html <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js') .then(reg => console.log('SW registered!', reg)) .catch(err => console.log('Error!', err)); } </script> <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js') .then(reg => console.log('SW registered!', reg)) .catch(err => console.log('Error!', err)); } </script> <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js') .then(reg => console.log('SW registered!', reg)) .catch(err => console.log('Error!', err)); } </script> <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js') .then(reg => console.log('SW registered!', reg)) .catch(err => console.log('Error!', err)); } </script> <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js') .then(reg => console.log('SW registered!', reg)) .catch(err => console.log('Error!', err)); } </script>
  • 33. 33 Register install activate fetch Making A Service Workers Register Service Worker Lifecycle install activate fetch
  • 34. Getting Started with Service Workers 34 // install self.addEventListener('install', event => { console.log('installing…'); }); // activate self.addEventListener('activate', event => { console.log('now ready to handle fetches!'); }); // fetch self.addEventListener('fetch', event => { console.log('now fetch!'); }); sw.js
  • 35. 35 Register install activate fetch Setting up the Default Cache Making A Service Workers
  • 36. Setting up the Default Cache 36 sw.js const filesToCache = [ '/', '/assets/images/btn_check.png', '/assets/images/btn_del.png', '/assets/images/ic_add.png', '/assets/images/logo_todo.png', '/src/main.css', '/index.html' ]; const cacheName = 'todolist-v1';
  • 37. Setting up the Default Cache 37 sw.js // install self.addEventListener('install', event => { console.log('installing…'); event.waitUntil( caches.open(cacheName).then(cache => { // console.log('Caching app ok'); return cache.addAll(filesToCache); }) ); }); // install self.addEventListener('install', event => { console.log('installing…'); event.waitUntil( caches.open(cacheName).then(cache => { // console.log('Caching app ok'); return cache.addAll(filesToCache); }) ); }); // install self.addEventListener('install', event => { console.log('installing…'); event.waitUntil( caches.open(cacheName).then(cache => { // console.log('Caching app ok'); return cache.addAll(filesToCache); }) ); }); // install self.addEventListener('install', event => { console.log('installing…'); event.waitUntil( caches.open(cacheName).then(cache => { // console.log('Caching app ok'); return cache.addAll(filesToCache); }) ); }); // install self.addEventListener('install', event => { console.log('installing…'); event.waitUntil( caches.open(cacheName).then(cache => { // console.log('Caching app ok'); return cache.addAll(filesToCache); }) ); });
  • 38. 38 Register install activate fetch Clearing Old Cache Making A Service Workers
  • 39. ` 39 // activate self.addEventListener('activate', event => { console.log('now ready to handle fetches!'); event.waitUntil( caches.keys().then(function(cacheNames) { var promiseArr = cacheNames.map(function(item) { if (item !== cacheName) { // Delete that cached file return caches.delete(item); } }) return Promise.all(promiseArr); }) ); // end e.waitUntil }); sw.js // activate self.addEventListener('activate', event => { console.log('now ready to handle fetches!'); event.waitUntil( caches.keys().then(function(cacheNames) { var promiseArr = cacheNames.map(function(item) { if (item !== cacheName) { // Delete that cached file return caches.delete(item); } }) return Promise.all(promiseArr); }) ); // end e.waitUntil }); // activate self.addEventListener('activate', event => { console.log('now ready to handle fetches!'); event.waitUntil( caches.keys().then(function(cacheNames) { var promiseArr = cacheNames.map(function(item) { if (item !== cacheName) { // Delete that cached file return caches.delete(item); } }) return Promise.all(promiseArr); }) ); // end e.waitUntil }); // activate self.addEventListener('activate', event => { console.log('now ready to handle fetches!'); event.waitUntil( caches.keys().then(function(cacheNames) { var promiseArr = cacheNames.map(function(item) { if (item !== cacheName) { // Delete that cached file return caches.delete(item); } }) return Promise.all(promiseArr); }) ); // end e.waitUntil }); // activate self.addEventListener('activate', event => { console.log('now ready to handle fetches!'); event.waitUntil( caches.keys().then(function(cacheNames) { var promiseArr = cacheNames.map(function(item) { if (item !== cacheName) { // Delete that cached file return caches.delete(item); } }) return Promise.all(promiseArr); }) ); // end e.waitUntil });
  • 40. 40 Register install activate fetch Handling Fetch Requests Making A Service Workers
  • 41. 41 <script> const list = document.getElementById('list'); // request fetch('http://localhost:3000/people') .then(res => { return res.json(); }) .then(json => { list.innerHTML = json .map(item => `<li>${item.name}</li>`) .join(''); }) </script> index.html Handling Fetch Requests
  • 42. Handling Fetch Requests 42 self.addEventListener('fetch', event => { event.respondWith( caches.match(event.request) .then(function(response) { return response || fetch(event.request) .then(res => caches.open(dataCacheName) .then(function(cache) { cache.put(event.request, res.clone()); return res; }) ); }) ); }); sw.js self.addEventListener('fetch', event => { event.respondWith( caches.match(event.request) .then(function(response) { return response || fetch(event.request) .then(res => caches.open(dataCacheName) .then(function(cache) { cache.put(event.request, res.clone()); return res; }) ); }) ); }); self.addEventListener('fetch', event => { event.respondWith( caches.match(event.request) .then(function(response) { return response || fetch(event.request) .then(res => caches.open(dataCacheName) .then(function(cache) { cache.put(event.request, res.clone()); return res; }) ); }) ); }); self.addEventListener('fetch', event => { event.respondWith( caches.match(event.request) .then(function(response) { return response || fetch(event.request) .then(res => caches.open(dataCacheName) .then(function(cache) { cache.put(event.request, res.clone()); return res; }) ); }) ); }); self.addEventListener('fetch', event => { event.respondWith( caches.match(event.request) .then(function(response) { return response || fetch(event.request) .then(res => caches.open(dataCacheName) .then(function(cache) { cache.put(event.request, res.clone()); return res; }) ); }) ); }); self.addEventListener('fetch', event => { event.respondWith( caches.match(event.request) .then(function(response) { return response || fetch(event.request) .then(res => caches.open(dataCacheName) .then(function(cache) { cache.put(event.request, res.clone()); return res; }) ); }) ); }); self.addEventListener('fetch', event => { event.respondWith( caches.match(event.request) .then(function(response) { return response || fetch(event.request) .then(res => caches.open(dataCacheName) .then(function(cache) { cache.put(event.request, res.clone()); return res; }) ); }) ); }); self.addEventListener('fetch', event => { event.respondWith( caches.match(event.request) .then(function(response) { return response || fetch(event.request) .then(res => caches.open(dataCacheName) .then(function(cache) { cache.put(event.request, res.clone()); return res; }) ); }) ); });
  • 43. 43
  • 44. 44
  • 46. 46
  • 47. 47
  • 48. 48
  • 49. 49
  • 50. 50
  • 51. PWA? PWA? Service Work Registering the Service Worker Setting up the Default Cache Clearing Old Cache Handling Fetch Requests PWA To-Do List - 51 2017 iT