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
87
DevOpsDays Taipei 2017 敏捷思維分享
chph
0
100
在 Google Cloud Platform 架設你的網站伺服器並撰寫 Node.js 應用程式
chph
0
670
Intro to Progressive Web Apps
chph
1
62
淺談 Gzip
chph
0
120
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
110
Other Decks in Technology
See All in Technology
今からでも間に合う! 生成AI「RAG」再入門 / Re-introduction to RAG in Generative AI
hideakiaoyagi
1
170
In Praise of "Normal" Engineers (LDX3)
charity
2
890
Rubyで作る論理回路シミュレータの設計の話 - Kashiwa.rb #12
kozy4324
1
300
宇宙パトロール ルル子から考える LT設計のコツ
masakiokuda
2
100
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
770
SFTPコンテナからファイルをダウンロードする
dip
0
200
Long journey of Continuous Delivery at Mercari
hisaharu
1
210
研究開発部メンバーの働き⽅ / Sansan R&D Profile
sansan33
PRO
3
17k
Securing your Lambda 101
chillzprezi
0
280
vLLM meetup Tokyo
jpishikawa
1
220
Javalinの紹介
notoh
0
110
Model Mondays S2E01: Advanced Reasoning
nitya
0
350
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.5k
Scaling GitHub
holman
459
140k
We Have a Design System, Now What?
morganepeng
52
7.6k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.7k
Statistics for Hackers
jakevdp
799
220k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.9k
Into the Great Unknown - MozCon
thekraken
39
1.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
Product Roadmaps are Hard
iamctodd
PRO
53
11k
RailsConf 2023
tenderlove
30
1.1k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Being A Developer After 40
akosma
90
590k
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/