waqasahmed996;10999504 wrote:
It looks that this is only solution
While it may look that way - it isn't.
Cookies have the downside of being transmitted on EVERY request, since they are always included among the http headers. If you do go with server side storage, I'd recommend storing it as session data and fetch it when it is undefined for the current document.
But you could also store the data in the browser instead, or store it there as well. There are two options for doing so.
You can use localStorage and/or sessionStorage which are properties of the window object. They are pretty much the same except that sessionStorage doesn't have same-origin policy while it is specific per "session" (i.e. browser tab or browser window). Thus, it's essentially the same as using window.name to store stuff if you need to cater to IE7-. All of which makes it a whole lote less interesting than localStorage in my opinion.
Warning: Same-origin policy dictates that access is only allowed for stuff coming from the same domain. Since there is no such restriction for sessionStorage, data stored there is accessible if the user goes somewhere else using the same tab, which also means that your data might have been overwritten before the user returns to your site, once again in the same tab.
localStorage could be implemented using cookie fallback for IE7- assuming you don't need to store too much data. While it's as easy to do as to handle sessionStorage in window.name, it also moves back from client side to server side which counterfeits the whole purpose. I believe MS had some propietary client side storage stuff for IE 6 +7.
There is existing code which implements fallbacks for local- and sessionStorage. As such, it's possible that someone actually implemented it using MS propietary stuff, but no certainty.
jQuery implements localStorage using cookies iirc.
Other than that, you should note that only string values can be stored, and thus any value, object, array which has been json-encoded can be stored. But this is important to remember for a number of reasons, such as
('1'+'2') - (1+2) == 9
It's also possible that you'd need to provide json encode and decode for IE 6/7. I've no idea if they had native support for it. But whatever you do, stay away from eval to decode json objects, especially if using session storage.