astoilkov/use-local-storage-state

Enhancment: use window.name as fallback

tilman opened this issue · 5 comments

Hey, just wanted to discuss the Idea of using window.name as a fallback instead of a global variable.

window.name would have the advantage of being persistent for the whole javascript session (in particular for a page reload; but not across tabs) and is still available even if cookies are turned off.

If you think that would be a better solution I would be happy to create a merge request.

Here is some more information about window.name:
https://www.thomasfrank.se/sessionvars.html

That's an interesting idea. I didn't know window.name worked like that. Can you help me by answering some questions?

  • When window.name is lost?
    • What about the different ways to refresh the page: using the address bar, using Reload Page, using Force Reload Page?
  • Is the behavior of window.name consistent between browsers?
  • Do you know some libraries that use window.name for persisting data?
  • Is it secure? Do iframes have access to the value?

@kolben I read the article. Thanks.

Why you wouldn't recommend it? What are the reasons? Thanks.

  • The original article linked is 13 years old.
  • The frameworks referenced in the mdn article are long gone and the article clearly says it shouldn't be used to store user data
  • window.name will very soon no longer be available across tabs/ windows

@kolben Yep. That's pretty definitive. Closing this issue then. Thanks!