I'm replacing cookies with localStorage on browsers that can support it (anyone but IE). The problem is site.com and www.site.com store their own separate localStorage objects. I believe www is considered a subdomain (a stupid decision if you ask me). If a user was originally on site.com and decides to type in www.site.com on her next visit, all her personal data will be inaccessible. How do I get all my "subdomains" to share the same localStorage as the main domain?
A:
I suggest making site.com redirect to www.site.com for both consistency and for avoiding issues like this.
Also, consider using a cross-browser solution like PersistJS that can use each browser native storage.
Eran Galperin
2010-10-26 18:00:55
I don't have admin access to the servers to do such a redirect. Does that library allow me to share persistent data between www and non-www? After doing some reading, it seems like nearly all browsers' storage mechanisms don't allow it. No matter if it's cookies or localStorage, we're going to run into this problem...
JoJo
2010-10-26 20:05:24
Yes, storage is normally dependent on the domain, including the subdomain. This is why I suggested a redirect. You don't necessarily need admin access, just use an .htaccess rule in the document root
Eran Galperin
2010-10-26 20:57:57