Progressive Web Apps 簡稱PWA,是一種接近原生使用者體驗的漸進增強的web-app.從浏覽器演進而來,沉浸式的體驗,改進web的性能低下等。是Google 在2015年提出,今年才推廣開來。其宗旨是漸進增強,不再有媲美原生應用的想法,而是讓 WebApp 變得更加對移動環境友好,體驗自然順滑。
目前移動web網頁的體驗
1. 手機桌面入口不夠便捷; 當然現在可以添加到主螢幕
2. 沒網絡就沒響應,不具備離線能力;
3. 不像APP一樣能進行消息推送。
PWA帶來的新特性
Progressive - Work for every user, regardless of browser choice because they’re built with progressive enhancement as a core tenet.
Responsive - Fit any form factor: desktop, mobile, tablet, or forms yet to emerge.
Connectivity independent - Service workers allow work offline, or on low quality networks. 可以離線,使用service worker技術,即使網頁關閉,PWA 仍然可以在背景運作擷取資料更新
App-like - Feel like an app to the user with app-style interactions and navigation.
Fresh - Always up-to-date thanks to the service worker update process.
Safe - Served via HTTPS to prevent snooping and ensure content hasn’t been tampered with.
Discoverable - Are identifiable as “applications” thanks to W3C manifests[6] and service worker registration scope allowing search engines to find them.
Re-engageable - Make re-engagement easy through features like push notifications. 可以推送消息
Installable - Allow users to “keep” apps they find most useful on their home screen without the hassle of an app store. 可以添加到home螢幕
Linkable - Easily shared via a URL and do not require complex installation. 便于分享
浏覽器支援情況
基于 Chromium 的浏覽器 Chrome 和 Opera 已經完全支援 PWA 了,Firefox 和微軟的 Edge 正在開發中,水果公司的 Safari 最近剛剛表達了可能會支援 PWA。從長久的角度看,隻要 Google 不斷推動一些網站往 PWA 轉型,其他的浏覽器或者競争對手也就會自然跟風上船。
怎麼實作?
實作 PWA 所需要的特性,主要是圍繞着 Service Workers 的基于事件的 cache 系統和消息推送的一套新的 API,此外還需要定義 manifest.json 來定義安裝行為或是樣式等。
體驗PWA
首先,将你的chrome更新到最新的55版本
1 合集
https://pwa.rocks/,這個網址有很多pwa應用。其中不乏 The Washington Post,Flip Board,AliExpress,Wikipedia,Gmail,Booking 這樣的大頭
2 阿裡巴巴
http://m.alibaba.com
和Hybrid App的差別
Hybrid App雖然看上去是一個Native App,但隻有一個UI WebView + Native的殼子,裡面通路的是一個Web App。而PWA是真正的Web App。
和微信小程式的差別
在 iOS 上,小程式的 javascript 代碼是運作在 JavaScriptCore 中,是由 WKWebView 來渲染的,環境有 iOS8、iOS9、iOS10
在 Android 上,小程式的 javascript 代碼是通過 X5 JSCore來解析,是由 X5 基于 Mobile Chrome 37 核心來渲染的
在 開發工具上, 小程式的 javascript 代碼是運作在 nwjs 中,是由 Chrome Webview 來渲染的
小程式入口在微信裡面,并不能添加到主螢幕,不能離線,不能推送。小程式的優勢就是龐大的使用者群,推廣起來非常好。
總而言之,PWA是未來的趨勢。
參考文章:
1. 我們真的需要網頁版App嗎?Google PWA的困局
2. https://github.com/hemanth/awesome-pwa#tutorials
3. https://developers.google.cn/web/progressive-web-apps/