Upgrade to Pro — share decks privately, control downloads, hide ads and more …

今更聞けないPWA

 今更聞けないPWA

PWAの基本となる部分をLTしました。(Gunma.web #38)

kanayannet

August 01, 2020
Tweet

More Decks by kanayannet

Other Decks in Programming

Transcript

  1. manifest file { "name": "pwa gunmaweb", "short_name": "pwa-gunmaweb", "icons": [

    { "src": "/icons/android-chrome-192x192.png", "sizes": "192x192", "type": "image/png", "purpose": "maskable" }, { "src": "/icons/android-chrome-512x512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
  2. service worker 記述する⾔語: JS JS だけど制約が⾊々ある 例: dom にアクセスできない o

    ine で表⽰可能などnative アプリっぽい挙動を可 能にする web のJS とは全く異なる制御をする
  3. service worker 読込⽅法 if ('serviceWorker' in navigator) { console.log('service worker

    is active'); navigator.serviceWorker.register('/sw.js').then(function (regis // 登録成功 console.log('ServiceWorker registration successful with scop }).catch(function (err) { // 登録失敗 :( console.log('ServiceWorker registration failed: ', err); }); }
  4. service worker 記述例 // self.addEventListener('install', function (e) { console.info('install', e);

    }); // self.addEventListener('activate', function (e) { console.info('activate', e); }); // self.addEventListener('fetch', function (e) { console.info('fetch', e); });