通过使用隐藏的div来缓存数据 [英] Caching data by using hidden divs

查看:140
本文介绍了通过使用隐藏的div来缓存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过执行以下操作来加快ajax Web应用程序中的响应时间:

假定用户请求内容不会更改的页面例如网页表单)。当用户提出不同的请求时,我通过将表单放入隐藏的div中来缓存表单。显示新信息之前。所以表单基本上仍然在浏览器中加载,但对用户不可见。如果用户再次请求相同的表单,它将从隐藏的div中加载。这显然比做表单服务器的往返速度要快得多。



我知道如果有很多数据,这样做会降低性能,因为浏览器需要保留记忆中很多。但我会限制这种方式获得缓存的数量。



现在,我自己想出了这个,这就是为什么我想知道如果有这样做的更好/已建立的方式。它按预期工作,但我不知道可能的缺点是什么(可能与安全有关?)。

我希望有任何建议。
非常感谢。

解决方案

我之前完成了这项工作。它可以是一种有用的技术。只需确保数据是准确的,并且您支持JS禁用的用户代理。

编辑:并没有更好的解决方案。


I'm trying to speed up response times in my ajax web application by doing the following:

Say the user requests a page whose contents don't change (e.g a web form). When the user makes a different request, I 'cache' the form by putting it in a hidden div. Before displaying the new information. So the form is basically still loaded in the browser but not visible to the user. If the user requests the same form again, it gets loaded from the hidden div. That's notably faster than doing a round-trip to the server for the form.

I do realise doing so with lots of data will probably degrade performance as the browser gets to keep a lot in memory. But I will place a limit on how much gets "cached" this way.

Now, I came up with this on my own which is why I'd like to know if there is a better/established way of doing this. It works as expected but I don't know what the possible drawbacks are (security-related perhaps?).

I would appreciate any suggestions. Many thanks.

解决方案

I've done this before. It can be a useful technique. Just make sure the data is accurate and that you support JS disabled user agents.

EDIT: And that there is no better solution.

这篇关于通过使用隐藏的div来缓存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆