If your users have a real account on which they log into the system on your server, you can save information on the server side and simply include a little javascript on each page that will need data with the corresponding data. When you create a page on the server side, you can define the user object in javascript with the corresponding attributes set to data values, which can then be specified on the client side. Thus, you include only the data that is needed on this page, the same user data is available, no matter which computer the user logs on to (do not rely on persistent cookies). If you need a large amount of data only occasionally, and you do not want to include it on the page if necessary, then make these pieces of data requested through ajax / json so that they can be received only when it was necessary.
If you still intend to store it only locally, then your cookies or HTML5 local storage are your only options, and cookies will be your only cross-browser option that will cover all browsers used. When adding complexity to the implementation, you can combine a number of suggestions:
- Always redirect to www.domain.com, so all user actions are in the same domain.
- Use local HTML5 storage, if available (redirecting in step 1 prevents blocking of subdomains).
- Return to the cookie store when local HTML5 storage is not available.
One could write or find an abstraction for local HTML5 storage and cookies, so 99% of your code can be independent of which storage engine was actually used. There seem to be some jQuery plugins that do just that.
jfriend00
source share