2016年3月5日 星期六
Service Workers
從 Service Worker API 節錄:Service workers essentially act as proxy servers that sit between web applications, and the browser and network (when available). They are intended to (amongst other things) enable the creation of effective offline experiences, intercepting network requests and taking appropriate action based on whether the network is available and updated assets reside on the server. They will also allow access to push notifications and background sync APIs.
要了解 Service Worker 的基本概念,可閱讀 Mozilla Developer 與 Google Developer。
這裡有一個簡單的示範。瀏覽該網頁之後,下次,即使拔掉網路線/關掉Wifi,仍然可以斷線的瀏覽它。換句話說,第一次瀏覽是連線瀏覽(online browse),以後就可斷線瀏覽(offline browse)。它的來源碼在這裡。
因為 Service Worker 會攔截 network request,基於安全理由,網頁必須以 https 為架構來確保資料的安全。換句話說,網頁以 http 為架構的,不能使用 Service Worker。然而,開發環境中,通常沒有 https 所需的憑證。Jeff Posnick 在 Options for testing service workers via HTTP 提到如何在 Chrome 與 Firefox 中測試使用 Service Worker 的網頁。
因為 Service Worker 會攔截 network request,基於安全理由,網頁必須以 https 為架構來確保資料的安全。換句話說,網頁以 http 為架構的,不能使用 Service Worker。然而,開發環境中,通常沒有 https 所需的憑證。Jeff Posnick 在 Options for testing service workers via HTTP 提到如何在 Chrome 與 Firefox 中測試使用 Service Worker 的網頁。
訂閱:
張貼留言
(
Atom
)
沒有留言 :
張貼留言