Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


Is this a GET request? What if my browser wants to peek ahead on some links?


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.


Image makes the HTTP request without appending the Image to the DOM? TIL


That's how most tracking scripts operate...


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.


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


Probably. I wonder though if they are trying not to use any libraries and Image was just easier than xhr.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: