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
Next.jsではじめるPWA
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
gyarasu
August 07, 2019
Technology
2
1.7k
Next.jsではじめるPWA
2019.08.07
『Sendai Frontend Meetup #1』の登壇資料です。
https://sfeug.connpass.com/event/137013/
gyarasu
August 07, 2019
Tweet
Share
More Decks by gyarasu
See All by gyarasu
QAエンジニア組織立ち上げはじめの一歩
gyarasu
0
74
Firebase Cloud Messaging のベストプラクティス を、探している
gyarasu
1
3.3k
RESTful Firebase with Vue.js
gyarasu
1
450
doda AIジョブサーチ PWAとパフォーマンスの話
gyarasu
0
1.8k
副業時代のプロジェクトマネジメント
gyarasu
3
3.1k
PWA基礎_1
gyarasu
0
310
PWA基礎_2
gyarasu
0
200
PWA基礎_3
gyarasu
0
170
フロントエンドエンジニア (実稼働まで) ひとりでできるもん
gyarasu
0
2.7k
Other Decks in Technology
See All in Technology
ブラックボックス観測に基づくAI支援のプロトコルのリバースエンジニアリングと再現~AIを用いたリバースエンジニアリング~ @ SECCON 14 電脳会議 / Reverse Engineering and Reproduction of an AI-Assisted Protocol Based on Black-Box Observation @ SECCON 14 DENNO-KAIGI
chibiegg
0
140
Agentic Software Modernization - Back to the Roots (Zürich Agentic Coding and Architectures, März 2026)
feststelltaste
1
170
技術的負債の泥沼から組織を救う3つの転換点
nwiizo
7
2.2k
管理者向けGitHub Enterpriseの運用Tips紹介: 人にもAIにも優しいプラットフォームづくり
yuriemori
0
110
問い合わせ自動化の技術的挑戦
recruitengineers
PRO
2
150
Eight Engineering Unit 紹介資料
sansan33
PRO
1
6.9k
LY Tableauでの Tableau x AIの実践 (at Tableau Now! - 2026-02-26)
yoshitakaarakawa
0
1.3k
Exadata Fleet Update
oracle4engineer
PRO
0
1.3k
パネルディスカッション資料 (at Tableau Now! - 2026-02-26)
yoshitakaarakawa
0
1.1k
「使いにくい」も「運用疲れ」も卒業する UIデザイナーとエンジニアが創る持続可能な内製開発
nrinetcom
PRO
1
780
組織のSREを推進するためのPlatform EngineeringとEKS / Platform Engineering and EKS to drive SRE in your organization
chmikata
0
180
Master Dataグループ紹介資料
sansan33
PRO
1
4.4k
Featured
See All Featured
Leo the Paperboy
mayatellez
4
1.5k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
150
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
63
How to make the Groovebox
asonas
2
2k
Accessibility Awareness
sabderemane
0
73
The SEO identity crisis: Don't let AI make you average
varn
0
400
Paper Plane (Part 1)
katiecoart
PRO
0
5.1k
It's Worth the Effort
3n
188
29k
Designing Experiences People Love
moore
143
24k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
620
Transcript
Next.jsではじめるPWA 2019/08/07 Sendai Frontend Meetup #1 吉次 洋毅
誰? • 吉次洋毅(ヨシツグヒロキ) • 1991年生まれ(27歳) • 経歴 ◦ 某レストラン検索サイトでバックエンドエンジニアなど ◦
某HR会社でエンジニアをしつつ ◦ フリーランスで受託開発&他社さんの開発やプロジェクトマネジメントのお手伝い • 趣味 ◦ 一人旅 & 写真 & スーパー銭湯 ◦ スマブラ(VIPボーダー周辺をウロウロ) ◦ 筋トレ @gyarasu
今日はNext.jsとPWAのお話
話すこと • ボイラープレートのご紹介 • Next.jsでPWAをするためのはじめの一歩 • Service Workerの導入でハマった話 • Nuxt.js×PWAとの比較
ボイラープレートのご紹介 https://github.com/gyarasu/nextjs-ts-pwa
Next.js×PWAはじめの一歩 まずは公式をチェック! https://nextjs.org/features/progressive-web-apps
next-offline https://github.com/hanford/next-offline
next-offline https://github.com/hanford/next-offline 中身はおなじみworkbox
next-offlineの使い方例 nextの設定ファイルにworkboxの オプションを記述できる。 (Runtime Cacheの例)
Next.js×PWAはじめの一歩 まずは公式をチェック! https://nextjs.org/features/progressive-web-apps これだけ!?
そうは問屋が卸さない
Service Worker導入で 少しハマった。
結論 • custom serverで/service-woker.jsをルーティングしてあげる必要があ る(上の例はExpress.js) • now v2(https://zeit.co/now, Lambdaに簡単にデプロイするための ツール)前提であれば特に何もしなくて良いとREADMEに書いてある
が、デプロイしてないと確認できない(少なくともローカルで動作確認で きない)
結論 • custom serverで/service-woker.jsをルーティングしてあげる必要があ る(上の例はExpress.js) • now v2(https://zeit.co/now, Lambdaに簡単にデプロイするための ツール)前提であれば特に何もしなくて良いとREADMEに書いてある
が、デプロイしてないと確認できない(少なくともローカルで動作確認で きない) アクセスURL 実際のファイルパス
結論 • custom serverで/service-woker.jsをルーティングしてあげる必要があ る(上の例はExpress.js) • now v2(https://zeit.co/now, Lambdaに簡単にデプロイするための ツール)前提であれば特に何もしなくて良いとREADMEに書いてある
が、デプロイしてないと確認できない(少なくともローカルで動作確認で きない) これをもうちょい掘り下げて Service Workerを理解する
Service Workerのscopeと生成先のパス デフォルトでは <project>/.next/service-worker に生成される
Custom Serverでルーティングせず/staticに置くと? /static/service-worker.jsで参照す ることが可能 ↓ しかし、SWがサイト全体をコント ロールすることができない
Service Workerのscope • 基本的にはサイト全体(/)をコントロールしたい →scopeを/にする • 一方で、static配下に置いた場合のアクセスURLは /static/service-worker.js • Service
Workerは自身が参照されるURLよりも上位の階層を コントロールできない
Service Workerを使うには Custom Serverで ルーティングを書く ※now v2う場合は不要 →https://github.com/hanford/next-offline#now-20
Nuxt.jsとの比較(Service Worker) Nuxtでは、@nuxt/pwaを使って簡単にPWA化できる https://pwa.nuxtjs.org Nuxt.js × @nuxt/pwa Next.js × next-offline
static/hoge.jsへの URL /hoge.js /static/hoge.js PWAモジュールを導入 した際のデフォルトの SW出力先パス <project>/static/sw.js <project>/.next/service-w orker.js SWのデフォルトscope / / 『Nuxt.jsとNext.jsの静的アセット、Next.jsにおけるService Worker導入』 https://scrapbox.io/gyarasu/Nuxt.js%E3%81%A8Next.js%E3%81%AE%E9%9D%99%E7%9A%8 4%E3%82%A2%E3%82%BB%E3%83%83%E3%83%88%E3%80%81Next.js%E3%81%AB%E3 %81%8A%E3%81%91%E3%82%8BService_Worker%E5%B0%8E%E5%85%A5
Nuxt.jsとの比較(その他) Nuxt.js × @nuxt/pwa Next.js × next-offline manifest.json manifest moduleが含まれてい
て、nuxt.config.jsに記述する manifest.json手作りして /staticに配置 →/pages/_document.jsxに参 照するためのlinkタグを追加 icon icon moduleが含まれていて 512x512の画像を用意し、必要 なサイズをnuxt.config.jsに記述 するとビルド時に生成してくれる 各サイズを自前で用意 push通知 one signal moduleが含まれて いる swのimport scriptを作成して pushするためのスクリプトを記 述
ボイラープレートでゆっくり見てください!
Pull Request お待ちしてます!
終