[英]Is 'Service Worker' support offline HTML form data?
Service Worker s essentially act as proxy servers that sit between web applications. Service Worker本质上充当位于Web应用程序之间的代理服务器。
My concern: Is ServiceWorker also support for offline forms? 我担心: ServiceWorker是否也支持离线表单? - If so then my other list of concerns are:
- 如果是这样,那么我的另一个问题清单是:
First off, service workers could potentially do a lot of things. 首先,服务工作者可能会做很多事情。 They have access to IndexedDB , for instance, so there's always the possibility of saving and loading arbitrary data, from the context of either a controlled page or a service worker.
例如,他们可以访问IndexedDB ,因此始终可以从受控页面或服务工作者的上下文中保存和加载任意数据。
But none of that will happen automatically by virtue of having an service worker registered—a service worker will, by default, do absolutely nothing. 但是,由于服务工作者已注册,服务工作人员默认情况下不会做任何事情,因此这些都不会自动发生。 It's only when you write code in the service worker to hook into different events (
install
, fetch
, message
, etc.) that things get interesting. 只有当你在服务工作者中编写代码以挂钩不同的事件(
install
, fetch
, message
等)时,事情才会变得有趣。
Hypothetically, if you were to write code in a service worker that cached an HTTP response for an HTML resource and then responded to fetch
events for the request's URL with that cached response, then the browser would get back and render the same HTML as it would if the response had come from the network. 假设,如果您要在缓存HTTP资源的HTTP响应的服务工作者中编写代码,然后使用该缓存的响应响应请求的URL的
fetch
事件,那么浏览器将返回并呈现相同的HTML。如果响应来自网络。 There wouldn't be any special "form state" that gets cached along with the HTML response body. 不会有任何特殊的“表单状态”与HTML响应主体一起缓存。
If, for some reason, you did want to save "form state" so that users who leave a page with a form could return and continue editing it, you'd have to do that independently of the caches
object that's exposed to the service worker. 如果由于某种原因,您确实想要保存“表单状态”,以便离开带有表单的页面的用户可以返回并继续编辑它,那么您必须独立于向服务工作者公开的
caches
对象执行此操作。 ( caches
requires that you use Request
objects as keys and stores Response
objects as values.) (
caches
要求您使用Request
对象作为键,并将Response
对象存储为值。)
So you could potentially do it using IndexedDB
, or you could do it using localStorage
, or really anything else. 所以你可以使用
IndexedDB
来做这件事,或者你可以使用localStorage
或其他任何东西来做。 It's independent of the service worker, and the particular privacy/security considerations are up to the implementer. 它独立于服务工作者,具体的隐私/安全考虑因素取决于实施者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.