开发者

How to cache an entire page save for one element

I'm running an e-commerce websit开发者_如何学Pythone and many pages are dynamic but for a widget displaying the number of items in the visitor's cart. I want to cache the page yet retain this dynamism. I'm considering caching the fragments before and after this widget but I was wondering if there was a simpler way to get this done.

Edit: Perhaps something which decided to give the cached page or not depending on whether the cart was empty or not would be a good start.

Kindest of Regards,

-- Jack


One way to do it is have the cart items displayed using JavaScript that's inserted after the page is loaded. You can see this on places like StackOverflow where your login status gets injected into the page if it wasn't already cached. jQuery can make this pretty straightforward.

You can set the number of items in a cookie accessible to JavaScript, not in the session hash as that's not exposed to the client, and handle that in the document.onload section.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜