简体   繁体   English

“服务工作者”是否支持离线HTML表单数据?

[英]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: - 如果是这样,那么我的另一个问题清单是:

  1. Where it stored the incomplete HTML form data at client side (Storage, Session, Local, Database)? 在客户端(存储,会话,本地,数据库)存储不完整的HTML表单数据的位置?
  2. In which form it stores user's filled data (encryption etc.) 以哪种形式存储用户填写的数据(加密等)
  3. How the data security/privacy tackled? 如何处理数据安全/隐私? that the returning user is the same user? 返回的用户是同一个用户? - if one user had filled out the form in public place and lost the internet connection and left the incomplete form and move on, now the next immediate user can see the incomplete form data, where the last user left the form. - 如果一个用户在公共场所填写了表格并丢失了互联网连接并留下了不完整的表格并继续前进,那么现在下一个直接用户可以看到不完整的表单数据,即最后一个用户离开表单的位置。

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. 只有当你在服务工作者中编写代码以挂钩不同的事件( installfetchmessage等)时,事情才会变得有趣。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM