Hacker News new | ask | show | jobs
by dspillett 3433 days ago
To an extent it might be worth letting those votes be lost to keep things simple, if only relatively few users browse that way.

There are ways around it if it were a problem though:

* Have a timeout on updates. If a vote has been sat in the local cookie send for some time send an XHR request to push the current queue to the server

* Use onunload event handlers to push any remaining queued votes when a tab closes. You could even try maintain a count of how many tabs are currently open (in the same cookie) and only send that request on the last one closing.

* If the amount of votes hits a certain length, also send a XHR request to register them.

Probably not perfect (I have in the past found onunload events to not be terribly reliable) but it would capture most of the otherwise lost votes you describe. It might be too much work to write/debug/maintain though, if the number of lost votes would be small anyway.