4 ms·
It's nothing more than an extra header or query param to denote an AJAX request. Then the server can respond with an empty 200/204 status code instead of the en
by manigandham 7y ago
It's nothing more than an extra header or query param to denote an AJAX request. Then the server can respond with an empty 200/204 status code instead of the entire HTML page. It's an hour of work and would actually save resources. None of this requires a front-end framework.
- xur17 7y agoYou'd need some frontend code to hide the upvote icon though.
- Deimorz 7y agoThat frontend code already exists and does that every time you vote (line 27 of https://news.ycombinator.com/hn.js https://news.ycombinator.com/hn.js). The response content isn't used for anything at all.
- zeta0134 7y agoNice! I hadn't actually looked at the code before writing my comment. That does seem relatively trivial, so I stand corrected. I didn't realize the clientside code was discarding the response; I sorta naively assumed it was doing a DOM replacement or something equally straightforward. What a pleasantly tiny script file. More site code should be this easy to read.
- samtheprogram 7y agoIf you have JavaScript disabled, the response content is used to hide the upvote sign.
- TeMPOraL 7y agoWe're talking here about something simple like: (if *ajax-request* (upvote) (upvote-and-generate-page))
- pmarin 7y agoHN works perfectly with javascript dissabled. It’s a feature
- IanCal 7y agoIt can still easily work with JavaScript disabled and implement the change.
- manigandham 7y agoWe're talking about it working better when JS is enabled.
- iforgotpassword 7y agoNo need for custom header or query param, Ajax (xmlhttp) requests already have an extra header field set automatically, so all is needed is some if statement server side, assuming registering the upvote and rendering the page is not entangled in some super crazy way.