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
高速傳愛~三小時進化 PWA
Search
chph
January 06, 2017
Technology
0
290
高速傳愛~三小時進化 PWA
高速傳愛 為台灣而教助學計畫 - 進化 PWA
chph
January 06, 2017
Tweet
Share
More Decks by chph
See All by chph
Chrome Dev Tools 基礎技巧
chph
0
89
DevOpsDays Taipei 2017 敏捷思維分享
chph
0
100
在 Google Cloud Platform 架設你的網站伺服器並撰寫 Node.js 應用程式
chph
0
690
Intro to Progressive Web Apps
chph
1
63
淺談 Gzip
chph
0
130
Install WordPress on Linode
chph
0
160
Introduction Infrastructure - Linode 入門
chph
0
220
Optimize JavaScript execution and parse time using optimize-js
chph
0
150
Modern Web 2016 議程分享: 網站自動化測試 - 以 PIXNET 搜尋 & 美妝口碑大賞為例
chph
0
120
Other Decks in Technology
See All in Technology
Claude Code でアプリ開発をオートパイロットにするためのTips集 Zennの場合 / Claude Code Tips in Zenn
wadayusuke
4
380
AIエージェント開発用SDKとローカルLLMをLINE Botと組み合わせてみた / LINEを使ったLT大会 #14
you
PRO
0
130
Django's GeneratedField by example - DjangoCon US 2025
pauloxnet
0
150
人工衛星のファームウェアをRustで書く理由
koba789
15
8.2k
Aurora DSQLはサーバーレスアーキテクチャの常識を変えるのか
iwatatomoya
1
1.2k
なぜスクラムはこうなったのか?歴史が教えてくれたこと/Shall we explore the roots of Scrum
sanogemaru
5
1.7k
EncryptedSharedPreferences が deprecated になっちゃった!どうしよう! / Oh no! EncryptedSharedPreferences has been deprecated! What should I do?
yanzm
0
480
AIエージェントで90秒の広告動画を制作!台本・音声・映像・編集をつなぐAWS最新アーキテクチャの実践
nasuvitz
3
330
共有と分離 - Compose Multiplatform "本番導入" の設計指針
error96num
2
1.1k
slog.Handlerのよくある実装ミス
sakiengineer
4
440
OCI Oracle Database Services新機能アップデート(2025/06-2025/08)
oracle4engineer
PRO
0
180
MagicPod導入から半年、オープンロジQAチームで実際にやったこと
tjoko
0
100
Featured
See All Featured
For a Future-Friendly Web
brad_frost
180
9.9k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.7k
Visualization
eitanlees
148
16k
Making the Leap to Tech Lead
cromwellryan
135
9.5k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
The Cult of Friendly URLs
andyhume
79
6.6k
A designer walks into a library…
pauljervisheath
207
24k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Why Our Code Smells
bkeepers
PRO
339
57k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Embracing the Ebb and Flow
colly
87
4.8k
Transcript
⾼速傳愛~三⼩時進化 PWA styleMe 會議室∘2017.01.06 afu @ 研發中⼼前端組 @afutseng
緣起 台灣⾼鐵董事⻑江耀宗上午將「台灣⾼鐵 ⾼速傳愛助學計畫」, 募得款項捐贈給「為台灣⽽教協會」,由協會執⾏⻑劉安婷代表接受 http://udn.com/news/story/9/2180211
先檢查⺫前缺什麼?
PWA Checklist • 網站具備 HTTPS 安全憑證 • ⾴⾯可以適應平板與⾏動裝置 • 可以離線載⼊
(⾄少⾸⾴) • 可以把網站加到⾏動裝置主畫⾯ • 3G 網路⾸次瀏覽限制在 10 秒內 … IUUQTEFWFMPQFSTHPPHMFDPNXFCQSPHSFTTJWFXFCBQQTDIFDLMJTU
HTTPS - Verify & Fix ! • 以瀏覽器驗證 SSL 憑證
• 沒有憑證怎麼辦? ! • 熟 Linux 操作約 2 ⼩時內可完成 IUUQTMFUTFODSZQUPSH
Let’s Encrypt 簽發的憑證 IUUQTMFUTFODSZQUPSH
Offline load: Verify
Offline load: Verify
Offline load: Fix ! ! ! ! IUUQTEFWFMPQFSTHPPHMFDPNXFCGVOEBNFOUBMTHFUUJOHTUBSUFEQSJNFSTTFSWJDF XPSLFST
ᅷยိݯɿIUUQTXXXJHWJUBDPNDBQBCJMJUZSFQPSUJOHXJUITFSWJDFXPSLFS
Offline load: Fix ! ! ! ! ᅷยိݯɿIUUQTEFWFMPQFSTHPPHMFDPNXFCGVOEBNFOUBMTHFUUJOHTUBSUFEQSJNFSTTFSWJDFXPSLFST
sw.js 怎麼來? • ⽅案⼀:⾃⼰寫 • ⽅案⼆:⾃動產⽣
Why & How ? • ⽅案⼆ - ⾃動產⽣ • 懶
• Service Worker Precache (by Chrome team) • 適合靜態網⾴,搭配 cache first 策略產出 sw.js IUUQTHJUIVCDPN(PPHMF$ISPNFTXQSFDBDIF
sw-precache • $ npm install --save-dev sw-precache IUUQTHJUIVCDPN(PPHMF$ISPNFTXQSFDBDIF
sw-precache 初版設定 sw-precache-config.js @@ -0,0 +1,12 @@ +module.exports = {
+ stripPrefix: 'webroot/', + staticFileGlobs: [ + 'webroot/index.php', + 'webroot/manifest.json', + 'webroot/img/**.*', + 'webroot/css/**.*', + 'webroot/js/**.*' + ], + swFile: 'sw-generated.js'
產出 service worker.js $ node_modules/sw-precache/cli.js —config=sw-precache-config.js Total precache size
is about 3.77 MB for 74 resources. webroot/service-worker.js has been generated with the service worker contents.
初版 sw.js 遇到的問題 • 僅靜態資源 (css/js/圖) 可離線存取 • ⾸⾴ (/)
無法離線存取 • 想更改產出的 server-worker.js 檔名 • 記得寫⼊ .gitignore,⾃動產出的檔案不進版本控制
sw-precache 設定 Ver. patch module.exports = { root: 'webroot/', stripPrefix:
'webroot/', directoryIndex: 'index.php', staticFileGlobs: [ 'webroot/index.php', 'webroot/manifest.json', 'webroot/sw-generated.js', 'webroot/img/**/*.*', 'webroot/css/**.*', 'webroot/js/**.*' ], swFile: 'sw-generated.js' };
看看成果吧!
None
可以繼續優化的部份 • 外部 CDN 的靜態資源也可提供離線存取 • Bootstrap, Font-awesome … etc
• 多數樣式已 inline 到 <head>,故視覺差異不⼤ • 導⼊ HTTP2 使多張圖⽚提早平⾏載⼊ • Lighthouse 有納⼊評核
Home screen - Verify & Fix • Verify: use Lighthouse
to verify "User can be prompted to Add to Home screen" is all Yes. • Fix: Add a Web App Manifest file to your project. IUUQTEFWFMPQFSTHPPHMFDPNXFCGVOEBNFOUBMTFOHBHFBOESFUBJOXFCBQQNBOJGFTU
Manifest.json 怎麼做? • ⽅案⼀:⾃⼰寫 • ⽅案⼆:⾃動產⽣ • https://brucelawson.github.io/manifest/ • https://app-manifest.firebaseapp.com/
Manifest.json
看看成果吧!
Add to Home screen • 只要 icon 與捷徑標題 相匹配表⽰正確讀取
manifest.json UIFNFDPMPS
Add to Home screen
啟動時的過場⾴
Benchmark overview 看看效能如何!
None
Lighthouse score (中華寬頻)
Lighthouse score (中華 4G)
Google PSI 速度指標
Yellow Lab Tools IUUQZFMMPXMBCUPPMTSFTVMUFMYRPRKNI
感謝聆聽 @afutseng
References 1. http://udn.com/news/story/9/2180211 2. https://developers.google.com/web/progressive-web-apps/ checklist 3. https://letsencrypt.org/ 4.
https://developers.google.com/web/fundamentals/getting- started/primers/service-workers 5. https://www.igvita.com/2014/12/15/capability-reporting- with-service-worker/ 6. https://github.com/GoogleChrome/sw-precache 7. https://www.webpagetest.org/ 8. http://yellowlab.tools/ 9. https://developers.google.com/speed/pagespeed/insights/