0

I have developed a web application and i am using browser local storage to save user data(public info). My problem is i have created 3 web application inside same domain with different site name,Eg:

https://www.domain.com/site1  - Dev
https://www.domain.com/site2  - Test
https://www.domain.com/site3  - Staging

My problem is when i tried to open these 3 website in different tab from same browser, i want to keep local storage data unique for each site(i;e; site1, site2, site3).

I know local storage data is stored against per domain, but is there any work around or approach to make it unique per site running on same domain.

Any help is appreciated.

Cyber
  • 4,844
  • 8
  • 41
  • 61
  • 1
    Is just using keys for separate objects in `LocalStorage` (or key prefixes) `"Dev"`, `"Test"` and `"Staging"` an option? – www0z0k Aug 11 '16 at 07:25
  • 1
    You could use the url (or parts of it) as a "separator" in the object `settings[window.location.pathname] = { ... };` – Andreas Aug 11 '16 at 07:25
  • Thanks for the comment www0z0k , Andreas. i have thaught of prefixing Env name in local storage, bu the problem here is for each deployment i need to make this changes. And also taking pathname is also a good suggestion ,but what if the pathname length exceeds some length. Anyway let me try this out. Appreciate your help. – Cyber Aug 11 '16 at 07:49
  • You may also extract just the last part of the url in some way like `"https://www.domain.com/site3".split('/').pop()` – www0z0k Aug 11 '16 at 09:45
  • The ["maximum" length of an URL (~2000)](http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers) is magnitudes smaller then the ["maximum" length of a property name (~2^27)](http://stackoverflow.com/questions/13367391/is-there-a-limit-on-length-of-the-key-string-in-js-object) – Andreas Aug 11 '16 at 11:22

0 Answers0