News for hackers. Stuff that matters.
Re:How true hackers write JavaScript by pygy_ on Wednesday September 05, 2018 @03:22AM (#17915734)
This is neat (how the up/downvote onclick handler sends the info to the server).

    new Image().src = el.href;
Where href looks like this:

    vote?id=xxxxxxxx&how=up&auth=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy&goto=item%3Fid%3Dzzzzzzzz#wwwwwwww
Re:How true hackers write JavaScript by lixtra on Wednesday September 05, 2018 @05:09AM (#17916282)
Is this a GET request? What if my browser wants to peek ahead on some links?
Re:How true hackers write JavaScript by arethuza on Wednesday September 05, 2018 @07:22AM (#17916894)
If the Image is being created dynamically there won't be anything for browser to peek ahead at.

Edit: I'd be more worried about repeated calls - but presumably the service being called is idempotent.

Re:How true hackers write JavaScript by lixtra on Wednesday September 05, 2018 @07:50AM (#17917047)
It's more the side effect of upvoting the whole thread that makes me wonder.

https://stackoverflow.com/questions/705782/why-shouldnt-data...

Re:How true hackers write JavaScript by pygy_ on Wednesday September 05, 2018 @06:43AM (#17916682)
This would indeed be problematic :-) The up/down vote buttons are plain anchor elements.
Re:How true hackers write JavaScript by expertentipp on Wednesday September 05, 2018 @08:52AM (#17917418)
Image makes the HTTP request without appending the Image to the DOM? TIL
Re:How true hackers write JavaScript by haywirez on Wednesday September 05, 2018 @09:07AM (#17917516)
That's how most tracking scripts operate...
Re:How true hackers write JavaScript by perfunctory on Wednesday September 05, 2018 @03:38AM (#17915823)
Maybe it's neat but this is not how anyone would write it today. This is the legacy code still left from the time before ajax was invented.
Re:How true hackers write JavaScript by TekMol on Wednesday September 05, 2018 @03:46AM (#17915872)
Hacker News was launched 2007.

XMLHttpRequest has been around for about 7 years then and using it was called Ajax for about 2 years already.

Re:How true hackers write JavaScript by qbonnard on Wednesday September 05, 2018 @03:56AM (#17915924)
Not to mention the "ajax" function in the script...
Re:How true hackers write JavaScript by pryce on Wednesday September 05, 2018 @04:14AM (#17916007)
It is strange. I wonder if it's an approach that lets duplicate vote attempts get automatically responded to by the webserver cache rather than passing through to be detected computationally at the application server level, which would also involve a DB call.

Conceivably this would make the architecture more robust against vote-spamming attacks, and the approach would also provide an enhanced version of this benefit if using an external caching reverse-proxy service like CloudFlare or similar (though I believe HN does not use CloudFlare).

This is complete supposition on my part.

Re:How true hackers write JavaScript by pygy_ on Wednesday September 05, 2018 @03:59AM (#17915944)
There's also an XMLHttpRequest wrapper for when they care about the response.

This is used for write-only GET requests (with graceful fallback when JS is disabled since those are plain anchor elements).

Re:How true hackers write JavaScript by winrid on Wednesday September 05, 2018 @03:46AM (#17915868)
Probably. I wonder though if they are trying not to use any libraries and Image was just easier than xhr.