开发者

is it possible to cache a dynamic web page?

Is it possible to cache a dynamic webpage if javascript is use开发者_开发百科d 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜