Chirag Khatsuriya
Chirag Khatsuriya

Reputation: 635

How to store cache in browser?

I want to store data in cache at browser side. But If I close the browser and I get back to my application I should get my Cached Data back,

Is this possible?

If Yes then How?

Upvotes: 0

Views: 2134

Answers (3)

Rob Trickey
Rob Trickey

Reputation: 1311

If you are happy with the browser support (check http://caniuse.com/#feat=namevalue-storage), you can use local storage to achieve this, which is much more powerful than cookies.

There are limits on how much you can store (varies by browser, but assume ~5Mb - compared with 4Kb per cookie), and it has the advantage over cookies that it is not sent to the server with every request. This adds a (slight) request overhead that you may not want.

Whichever solution you go for, make sure you handle the case that the user has cleared out all this data, or maybe just some of it....

Upvotes: 2

techfoobar
techfoobar

Reputation: 66693

Use HTML5 local storage.

Ref: http://diveintohtml5.info/storage.html

Upvotes: 0

pyrometer
pyrometer

Reputation: 881

You can use cookies to store data and retrieve it the next time user opens your webpage.

For example -

Use this snippet to capture the data of some textfield into a cookie -

   $.cookie("mydata", $(".sometextfield").val(), {expires: 7});

Now suppose the user closes the browser.

The next time a user visits your page, his snippet will read the cookie data and populate the textfield on page load -

  $(".sometextfield").val( $.cookie("mydata") );

Upvotes: 1

Related Questions