---
title: 网络独立
slug: Web/Progressive_web_apps/Network_independent
tags:
- Application Shell
- IndexedDB
- PWA
- Progressive web apps
- Service Workers
- Web Storage
- localStorage
translation_of: Web/Progressive_web_apps
---
当网络不可靠,甚至不存在时,现代网络应用程序仍可以工作。没有更多的空白连接错误页面或恐龙穿过沙漠。除了离线高速缓存和服务工作者之外,UI和内容之间的一个明确的分隔可让您存储应用程序的数据和核心资产,以备将来使用。
The basic ideas behind network independence are to be able to:
- Revisit a site and get its contents even if no network is available.
- Browse any kind of content the user has previously visited at least once, even under situations of poor connectivity.
- Control what is shown to the user in situations where there is no connectivity.
核心指南
- Using service workers
- A simple guide for those new to the Service Worker API.
- Using IndexedDB
- The basics of IndexedDB, explained in detail.
- Using the Web Storage API
- The Web storage API made simple.
- Instant Loading Web Apps with An Application Shell Architecture
- A guide to using the App Shell coding pattern to create apps that load quickly.
技术
技术 |
描述 |
支持概览 |
最新规范 |
Service workers |
JavaScript running in a special worker context that is run by the browser under certain circumstances such as fetch or push events. These allow the service worker to intercept responses and customise them in any way you want, for example caching assets for offline use before they are served. |
Experimental: Chrome and Firefox (more detail) |
{{SpecName('Service Workers')}} |
IndexedDB |
A transactional database system that allows complex client-side data storage to be controlled via JavaScript. |
Widespread across modern browsers (more detail) |
{{SpecName('IndexedDB')}} |
Web Storage |
A simple API for storing name-value pairs on the client-side. |
Widespread (more detail) |
{{SpecName('Web Storage')}} |
工具
- localForage
- A nice simple JavaScript library for making client-side data storage really simple; it uses IndexedDB by default, and falls back to Web SQL/Web Storage if necessary.
- ServiceWorkerWare
- An Express-like microframework for easy Service Worker development.
- oghliner
- Not only a template but a tool for deploying Offline Web Apps to GitHub Pages.
- sw-precache
- A node module to generate service worker code that will precache specific resources.
- upup
- A tiny script that makes sure your site is always there for your users.
参见
- The service worker cookbook
- A series of excellent service worker recipes, showing how to implement an offline app, but also much more.