是否可以缓存动态网页?
如果使用 javascript 更改显示或将新的 innerHTML 写入页面,是否可以缓存动态网页。例如,也许某些 ajax 会运行并从数据库中获取一些信息,然后通过重写 div 的 innerHTML 动态显示在页面上。
是否可以缓存最终的 html 并提供它,而不是每次都重新创建它。 谢谢,
丹
Is it possible to cache a dynamic webpage if javascript is used to alter the display or write new innerHTML into the page. For example maybe some ajax runs and fetches some info from the database that is then displayed dynamically on the page by rewriting the innerHTML of a div.
Is it possible to cache the final html and serve that up instead of recreating it each time.
Thanks,
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的当然。
自动完成文本输入框通常会缓存结果,以便按退格键或删除键不会将请求重新发送到服务器。
怎么做呢?只需从 DOM 树读取
innerHTML
并将其保存在 JavaScript 变量中甚至 HTML5 本地存储中。Yes, of course.
It is common with auto-complete text input boxes to cache the results so that hitting backspace or delete does not re-send requests to the server.
How to do it? Just read
innerHTML
from the DOM tree and save somewhere, in a JavaScript variable or even in HTML5 local storage.这实际上取决于您的页面实际上的动态程度,特别是如果您通过 ajax 请求显示与用户直接相关的信息,即“G'Day Flungabunga,澳大利亚悉尼情况如何”。
根据我的经验,用于实现缓存这些结果并仍然维护 javascript 作为核心机制的解决方案和技术变得过于复杂和脆弱。
为了实现这种行为并能够有效地缓存这些结果,我们采用了 Varnish Cache 及其 ESI(边缘包含)功能。
我知道这个答案在某种程度上偏离了主题,但是您可能会发现查看不同的机制可能会给您带来更优雅的解决方案。
It really depends on how dynamic your page actually is especially if you're displaying information directly relating to the user, i.e. "G'Day Flungabunga, how are thing's in Sydney, Australia" by means of an ajax request.
In my experience the solutions and techniques employed to achieve caching of these results and still maintaining javascript as the core mechanism became overly complicated and brittle.
To achieve this kind of behaviour and be able to cache these results effectively we employed Varnish Cache and it's ESI (Edge Side Includes) capabilities.
I know this answer if off topic to some degree, however you may find that looking at a different mechanism may give you a more graceful solution.