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).
Where href looks like this:
[ Parent
| on HN ]
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.
It's more the side effect of upvoting the whole thread that makes me wonder.
https://stackoverflow.com/questions/705782/why-shouldnt-data...
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.
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...
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.
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).