开发者

Basic caching question

I am displaying data from JSON file (on another server) on my site with jquery.

How should I go about caching? Caching in jquery or caching the JSON files?开发者_如何学Python

Can you point me in the right direction?

Polling and updating the JSON file once per hour would be enough.

Thanks!


Assuming the problem you're trying to solve is data that might be used by multiple different pages that you don't want to have to re-request more than once an hour.

If the data is not too large, you could save it in a cookie and set a one hour expiration on the cookie.

If this is all in one page, then you can just keep track of the last time you requested the data.

If the data is not small enough for a cookie and is across pages, you could look into HTML5 local storage which would be an optimization that would only work in modern browsers and fall back to requesting a new copy of the data when local storage was not supported.


Caching in jQuery won't help you much if there are multiple clients or the pages are refreshed. Caching the JSON files' contents on the server side might improve performance as the files are not read, only the server memory.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜