4 ms·
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.
by perfunctory 8y ago
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.
- winrid 8y agoProbably. I wonder though if they are trying not to use any libraries and Image was just easier than xhr.
- TekMol 8y agoHacker News was launched 2007. XMLHttpRequest has been around for about 7 years then and using it was called Ajax for about 2 years already.
- qbonnard 8y agoNot to mention the "ajax" function in the script...
- pygy_ 8y agoThere'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).
- pryce 8y agoIt 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.