Live data from Hacker News

Inter-window messaging using localStorage

bens.me.uk

11–20 of 30 posts

Re: Inter-window messaging using localStorage

#11
post #8

localStorage doesn't clear when the browser exits so it's a security issue in some cases. Look at sessionStorage instead in that case.

sessionStorage won't work across tabs. You have to encrypt sensitive data; I use securecookie [0].

[0] http://godoc.org/github.com/gorilla/securecookie (Go)

Re: Inter-window messaging using localStorage

#12

Earlier quoted context omitted.

I am disappointed I did not have an original thought. Nothing is new in this world. I propose we rename it the "Web Storage And Messaging" API.

Don't be disappointed! This is slick, and easy to understand. I don't really want to digest the javascript Facebook is using to learn a new tool/concept.

Thank you. I was impressed with how few lines of code were needed to use the API, always a sign of a well-designed system.

Re: Inter-window messaging using localStorage

#13
post #8

localStorage doesn't clear when the browser exits so it's a security issue in some cases. Look at sessionStorage instead in that case.

Yes, there are potential security issues with this, but as with anything in the browser you need to think through where your secrets are held. A similar issue comes with setting an expiry time of a few hours on a resource to let the browser cache it, so it's something web developers have been battling against for years.

Re: Inter-window messaging using localStorage

#14
post #9

Great idea. Doesn't seem to work in Chrome on iOS?

http://caniuse.com/#search=localStorage needs another column.

I was intending this to be a "nice to have if it works", rather than essential to my app. But do people really use multiple tabs on a single site that much on mobile devices?

Re: Inter-window messaging using localStorage

#15
post #2

This isn't abuse, it's what the storage event was specifically made for. Facebook, Google, etc. have been using this event to update common state information between tabs for quite a while.

I am disappointed I did not have an original thought. Nothing is new in this world. I propose we rename it the "Web Storage And Messaging" API.

No worries. We all stand on the shoulders of giants. :)

Re: Inter-window messaging using localStorage

#17
post #4

If you want to use localStorage atomically, I found this writeup and code on a LockableStorage interface to be very thorough: http://balpha.de/2012/03/javascript-concurrency-and-locking-...

It depends on what you mean by atomic. Please refer to http://www.chromium.org/developers/design-documents/indexedd... where Chromium devs state: """ LocalStorage is inherently racy or a parallelism disaster, depending on whether or not you're willing to implement the "storage mutex" described in the spec. Chromium has decided not to implement it. WebKit itself is single thread/process (i.e. no parallelism period). """

Note that the way Chromium implements localStorage, it uses a disk backing store of sqlite, a caching layer (a std::map) in the browser process, and a caching layer (also a std::map) in the renderer processes (where WebKit runs, and may handle 1-X tabs per process). Changes are propagated via IPC, but as the API does not provide any locking guarantees beyond the optional storage mutex, which Chromium does not implement, there are obviously race conditions.

This probably explains the issues the author of that post encountered with Chrome.

Re: Inter-window messaging using localStorage

#18
post #4

If you want to use localStorage atomically, I found this writeup and code on a LockableStorage interface to be very thorough: http://balpha.de/2012/03/javascript-concurrency-and-locking-...

It depends on what you mean by atomic. Please refer to http://www.chromium.org/developers/design-documents/indexedd... where Chromium devs state: """ LocalStorage is inherently racy or a parallelism disaster, depending on whether or not you're willing to implement the "storage mutex" described in the spec. Chromium has decided not to implement it. WebKit itself is single thread/process (i.e. no parallelism period). "…

The storage mutex is still technically in the spec, but no browser is going to implement it.

Re: Inter-window messaging using localStorage

#20
post #6

Earlier quoted context omitted.

I am disappointed I did not have an original thought. Nothing is new in this world. I propose we rename it the "Web Storage And Messaging" API.

Maybe you didn't invent the idea, but your post will likely introduce the concept to many folks. I believe this is equally valuable. Thanks.

TIL that you can do this. Awesome.
Post reply on HN