3 ms·
On mobile so can’t check but from memory there is very simplistic JavaScript on the pages and the vote buttons are just links (maybe form Post buttons) that re
by samwillis 5y ago
On mobile so can’t check but from memory there is very simplistic JavaScript on the pages and the vote buttons are just links (maybe form
Post buttons) that return a http 204 (no content) response that effectively stops the browser from doing anything. The vote counts is just a preemptive ui update with no error checking.
It’s always been this way.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204 https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204
- colejohnson66 5y agoYep. They're simply <a> tags. The code inside `onclick` is very primitive: if (u.pathname == '/vote') { vote(p.get('id'), p.get('how'), p.get('auth'), p.get('goto')); } `vote` just sees if it's an up or a down, set's the unvote link's `innerHTML`, then, curiously, uses an `Image` object to make the request: new Image().src = vurl(id, how, auth, _goto); The code is only 152 lines and is very easy to read: https://news.ycombinator.com/hn.js https://news.ycombinator.com/hn.js
- zarzavat 5y agoThe Image makes sense as a way to make HTTP requests before XMLHttpRequest was widely supported.
- matt_kantor 5y agoHacker News isn't that old. It launched in 2007 at which point XMLHttpRequest had been implemented in all major browsers for several years.
- zarzavat 5y agoOn the desktop yes, but it was on the cusp of the smartphone era so there were many weird mobile browsers around.
- colejohnson66 5y agoThe advantage of XMLHttpRequest is that you get feedback through a callback. When the user clicks the vote arrows, they could turn into something else (such as a spinner) that would disappear when the API request finishes. If my internet is spotty, having some feedback (so I know my votes didn't timeout) would be nice.
- deleted 5y ago[deleted]