Share
Embed
GDG神戸 Progressive Web Appハンズオン勉強会
GDG神戸 Progressive Web Appハンズオン勉強会の資料です。
Yosuke Onoue
July 30, 2016
Transcript
34 slides
-
͡Ίʹ • Progressive Web Apps (PWA)ͷϋϯζΦϯษڧձͰ͢ • ϋϯζΦϯͱ͘͘λΠϜΛ௨ͯ͡PWAΛମݧ͠·͢ • HTMLɺJavaScriptΛͬͯ։ൃ͠·͢
• Android or ΤϛϡϨʔλ͕͋ΔͱΑΓָ͍͠Ͱ͢ -
ࣗݾհ • ͓ͷ͏͑ (@_likr) • ژେֶ ֶࡍ༥߹ڭҭݚڀਪਐηϯλʔ ࡦͷͨΊͷՊֶϢχοτ ಛఆॿڭ •
GDGਆށελοϑɺng-kyotoΦʔΨφΠβʔ • ՄࢹԽɺ࠷దԽɺΞϧΰϦζϜͷݚڀ • WebϑϩϯτΤϯυ։ൃ -
λΠϜςʔϒϧ ࣌ؒ ༰ ʙ Φʔϓχϯά ʙ 18"ͷհ ʙ ϋϯζΦϯ ʙɹ
͘͘λΠϜ ʙ Ռൃද ҙ ʙ εϙϯαʔτʔΫΫϩʔδϯά -
ڥ • Google Chrome https://www.google.co.jp/chrome/browser/desktop/ • Web Server for Chrome
https://chrome.google.com/webstore/detail/ ofhbbkphhbklhfoeikjpcbhemlocgigb • Node.js https://nodejs.org/ • ΈͷςΩετΤσΟλ -
Progressive Web Apps • https://developers.google.com/web/progressive- web-apps/ • WebαΠτͱωΠςΟϒΞϓϦͷ ͍͍ͱ͜औΓΛͨ͠WebΞϓϦ •
Progressive Enhancement • ߴ͍ϢʔβϏϦςΟͷ࣮ݱ • ϏδωεϑϨϯυϦʔ -
PWAͰͰ͖Δ͜ͱ • ΦϑϥΠϯԽ • Πϯλʔωοτଓͳ͠Ͱͷར༻ • දࣔͷߴԽ • Push௨ •
ΞϓϦͷ࠶๚Λଅਐ • App Install Banner • ϗʔϜը໘ͷγϣʔτΧοτՃ • ঃʑʹΞϓϦͷΑ͏ʹͳΔʂ -
ؔ࿈Ωʔϫʔυ • Responsive Design • RAIL Performance Model • Web
Storage / IndexedDB • ϞδϡʔϧγεςϜ • webpackɺSystemJSɺ… • ϑϩϯτΤϯυϑϨʔϜϫʔΫɺϥΠϒϥϦ • AngularɺPolymerɺReactɺ… -
ࠓੲ… • Application Cache • Offline Web ApplicationsΛ࣮ݱ͢ΔͨΊͷΈ • cache
manifestͰΩϟογϡ͢ΔϦιʔεΛࢦఆ • Application CacheͷηΩϡϦςΟ by @kyo_ago http://0-9.sakura.ne.jp/pub/w3cdev/start.html • ݱࡏඇਪɺকདྷతʹഇࢭ • JavaScriptͰॊೈͳ੍ޚ͕ՄೳͳServiceWorker -
Service Workerͱ • Webϖʔδ(ϝΠϯεϨουɺUIεϨου)ͱ ಠཱͯ͠εΫϦϓτΛಈ࡞ͤ͞ΔΈ • ωοτϫʔΫϦΫΤετΛϑοΫ • ΩϟογϡΛͬͯϨεϙϯε •
ϦΫΤετΛमਖ਼ • αʔόʔPushΛड͚ͯ௨Λදࣔ • postMessageͰϝΠϯεϨουͱ௨৴ • HTTPSͰͷΈಈ࡞ (localhostΛআ͘) -
ͳͥΦϑϥΠϯWebΞϓϦʁ • ϞόΠϧڥͷରԠ • ௨৴ͷෆ҆ఆ͞ • ௨৴ͷޮԽ • ޫෆมʂ •
ΦϑϥΠϯɾϑΝʔετͷࢥͱ࣮ફ by നੴढ़ฏ http://www.slideshare.net/shumpei/thought-and- practice-of-offline-first -
Service Workerͷαϙʔτঢ়گ • Desktop • Firefox • Chrome • Opera
• Mobile • Android Browser • Chrome for Android • http://caniuse.com/#feat=serviceworkers -
Service Workerͷొ • navigator.serviceWorker.registerΛ༻ • Service Workerະαϙʔτڥ navigator.serviceWorkerͷ༗ແΛ֬ೝ • ॏෳొؾʹ͠ͳͯ͘OK
if ('serviceWorker' in navigator) { navigator.serviceWorker .register('./service-worker.js') .then(() => { console.log('Service Worker Registered’) }) } -
Service Workerͷ࣮ • ΠϕϯτϋϯυϥͰॲཧΛ࣮ • ϖʔδ͕ඇΞΫςΟϒͰಈ࡞ self.addEventListener(‘install’, (event) => {
// workerͷΠϯετʔϧ }) self.addEventListener(‘activate’, (event) => { // workerͷactivate }) self.addEventListener(‘fetch’, (event) => { // ωοτϫʔΫΞΫηεͷϑοΫ }) self.addEventListener(‘message’, (event) => { // ϝΠϯεϨου͔Βͷϝοηʔδड৴ }) -
Cache • ੩తΩϟογϡɿinstallΠϕϯτͰॲཧ • ಈతΩϟογϡɿfetchΠϕϯτͰॲཧ let cacheName = ‘pwa-example’ let
filesToCache = [/* urls */] self.addEventListener(‘install’, (event) => { console.log(‘[ServiceWorker] Install’) event.waitUntil(caches.open(cacheName).then((cache) => { console.log(‘[ServiceWorker] Caching app shell’) return cache.addAll(filesToCache) })) }) -
Push௨ • WorkerͰϝοηʔδड৴ͯ͠௨Λදࣔ • ૹ৴ʹGoogle Cloud Messaging (GCM)Λ༻ self.addEventListener(‘push’, (event)
=> { console.log(‘Push message’, event); let title = ‘Push message’ event.waitUntil( self.registration.showNotification(title, { body: ‘The Message’, icon: ‘images/icon.png’, tag: ‘my-tag’ })) }) -
Service Workerͷσόοά • Developer Tools • Ωϟογϡͷ֬ೝɺૢ࡞ • Workerίʔυͷσόοά •
Push௨ͷςετ • chrome://serviceworker-internals • Workerͷఀࢭɺొղআ -
Fetchઓུ • The offline cookbook https://jakearchibald.com/2014/offline-cookbook/ • Cache only •
Network only • Cache, falling back to network (cache first) • Cache & network race (fastest) • Network falling back to cache (network first) • … -
sw-precache • https://github.com/GoogleChrome/sw-precache • JavaScript·ͨઃఆϑΝΠϧ͔Β Service WorkerίʔυΛੜ • Α͘͏Fetchઓུ͕࣮ࡁΈ •
networkFirst • cacheFirst • fastest • cacheOnly • networkOnly -
͓·͚ (্ڃऀ͚ʁ) • Γ͍ͨ͜ͱ • AltJSͰService WorkerΛ࣮͢Δ • Service WorkerͰnode.jsϞδϡʔϧΛར༻͢Δ
• UIεϨουͱService WorkerͷίʔυΛڞ௨Խ͢Δ • WorkerΛۦ͢ΔͨΊͷϓϩδΣΫτߏ with webpack http://qiita.com/_likr/items/d382dc120a942ba4c6fe -
ͬͯΈͨ • Angular & WordPress.com APIͰ࣮ͨ͠ϒϩά • https://likr.github.io/blog • https://github.com/likr/blog
• ͬͨ͜ͱ • Service WorkerʹΑΔΦϑϥΠϯରԠ • sw-precache༻ • هࣄnetwork firstͰऔಘ • ϗʔϜεΫϦʔϯͷՃ -
ϋϯζΦϯ༰ • Your first Progressive Web App • ӳޠɿhttps://codelabs.developers.google.com/ codelabs/your-first-pwapp/index.html
• ຊޠɿhttps://codelabs.developers.google.com/ codelabs/your-first-pwapp-ja/index.html -
͓͢͢ΊCodelab • ॳڃ • Add Your Web App to a
User’s Home Screen • Migrate your site to a Progressive Web App • தڃ • Caching with progressive libraries • Enable Push Notifications for your Web App • ্ڃ • Building data-rich web apps with Lovefield • Building a Progressive Web app with Firebase, Polymerfire and Polymer Components -
ࢀߟใ • Progressive Web Apps https://developers.google.com/web/progressive- web-apps/ • Progressive Web
App Dev Summit 2016 https://events.withgoogle.com/progressive-web-app- dev-summit/