Live data from Hacker News

Inter-window messaging using localStorage

bens.me.uk

1–10 of 30 posts

Re: Inter-window messaging using localStorage

#3
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.

Re: Inter-window messaging using localStorage

#5
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-...

That's rather cool. And nice to see a use of the Lamport algorithm in a browser. :-)

Re: Inter-window messaging using localStorage

#6
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.

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.

Re: Inter-window messaging using localStorage

#7
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.

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.

Re: Inter-window messaging using localStorage

#10
The primary caveat with this approach is race conditions due to lack of locking. Note the "Issues" section in http://www.w3.org/TR/webstorage/ which says:

""" The use of the storage mutex to avoid race conditions is currently considered by certain implementors to be too high a performance burden, to the point where allowing data corruption is considered preferable. Alternatives that do not require a user-agent-wide per-origin script lock are eagerly sought after. If reviewers have any suggestions, they are urged to send them to the addresses given in the previous section.

More details regarding this issue are available in these e-mails (as well as numerous others):

http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-Sep... http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-Dec... """

So as long as you don't need transactions/locks across the shared state, this might work. Of course, transactions/locks are often necessary.

Post reply on HN