github:即使重新加载浏览器,评论仍然存在,为什么?

时间:2017-08-31 14:29:23

标签: github frontend

当我用github的问题页面写评论时,我注意到即使我重新加载浏览器,评论正文仍然存在。

enter image description here

我检查过localStorage,sessionStorage,cacheStorage,IndexedDB,cookie, 但我没有发现我写的那句话的实例。

另外,我检查了Chrome Devtool的网络标签,但我找不到任何可疑的网络流量。

github.com如何实现此恢复功能?

1 个答案:

答案 0 :(得分:1)

他们正在使用SessionStorage来做到这一点:

页面离开

  1. 使用.js-session-resumable作为选择器选择所有输入字段
  2. 将{id,value}对输入放入数组
  3. 将其作为SessionStorage放入session-resume:/current/page/path

页面加载:

  1. session-resume:/current/page/path中的SessionStorage键检查是否有任何值
  2. 如果是,请更新输入值并从SessionStorage删除此记录

注意::如果您在页面中写评论(不提交)并转到另一页面,那么您可以看到您的评论保存在SessionStorage中。