Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do subdomains share local storage?

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?

  1. www.website.com
  2. admin.website..com

Due to the nature of the apps, I do not want their local storage to be shared and hoping this is the default behaviour.

like image 200
Charklewis Avatar asked Dec 22 '18 04:12

Charklewis


People also ask

Can subdomains access local storage?

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.

Is local storage specific to domain?

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.

What is the benefit of using subdomain?

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.

Is a subdomain a separate domain?

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.


1 Answers

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 :)

like image 180
Matthew Herbst Avatar answered Nov 04 '22 04:11

Matthew Herbst