I'm currently building two react apps with both storing a redux state in local storage.
Will the example domains below share the same local storage?
Due to the nature of the apps, I do not want their local storage to be shared and hoping this is the default behaviour.
The storage is bound to the origin (domain/protocol/port triplet). That is, different protocols or subdomains infer different storage objects, they can't access data from each other.
Since localStorage stores key-value pairs that are domain specific, you'd quickly run into problems if you host multiple apps on the same domain, all of which are making use of local storage to store some of their app specific data.
Benefits of Subdomains Subdomains can be used to target a specific market segment, reading group, or country. Google often gives ranking preference to sites with strong topical authority within a targeted niche. The ability to utilize a keyword for clarity, search engine optimization, and promotional purposes.
While a subdomain is part of the main website, it's considered a separate entity by search engines. People recognized this and decided to use subdomains to organize their website, without allowing certain parts of the site to be indexed by Google. Companies use subdomains for a variety of reasons.
localStorage
is based on a Document's origin. For example, the origin of this page is:
self.origin; // "https://stackoverflow.com"
So, no, localStorage
will not be shared across subdomains. If you did want to share localStorage
across sub-domains, there is a solution here on SO for that :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With