4 ms·
I assume you have JavaScript disabled, right? If so, can you give an example of a similar webpage that doesn’t reload the whole page to reflect your vote?
by ezequiel-garzon 7y ago
I assume you have JavaScript disabled, right? If so, can you give an example of a similar webpage that doesn’t reload the whole page to reflect your vote?
- Deimorz 7y agoNo, voting doesn't work at all with JS disabled.
- icebraining 7y agoYes, it does. I think you have something weird with your browser: with JS on, it does a light AJAX request, without it, it does the whole redirect thing.
- oplav 7y agohttps://i.imgur.com/9z2VAfa.png https://i.imgur.com/9z2VAfa.png These are my network requests when I vote with JS enabled.
- manigandham 7y agoThe request is the same. The buttons are <a> tags. Without JS, the link is clicked and does a full page reload. With JS, the click is caught and sent as a AJAX request where the response is ignored. It's not any lighter, it's just not reloading the page.
- Deimorz 7y agoWhoops, you're right, it does work either way. The response is the same with or without JS though, it just doesn't do anything with it when JS is enabled (because as a hacky way of doing "AJAX" it sets the voting url as the src value of an <img> tag that doesn't actually get displayed).
- cynwoody 7y agoVoting does work with JS disabled, just not well. The page reloads and re-renders with the UI changes (up-down buttons hidden and unvote link added). However, the reload takes noticeable time, and you lose your scroll location, which is disorienting. With JS enabled, the UI changes happen instantly, and the scroll position doesn't change. The page still reloads, but the reload is directed into a new Image object which is immediately garbage, so it's off the UI timeline. But it's inexplicable bandwidth waste, nonetheless!
- crispyporkbites 7y agoYou can do this without javascript, you just create a form that sends an XHR PUT/POST request and returns back a 200 response. You can't do much with the response without JS but a single upvote doesn't change anything on the page so there's no need for the reload.
- icebraining 7y ago> a single upvote doesn't change anything on the page Not much, but it does hide the arrows and shows an undo link on the comment.
- nothrabannosir 7y agoNo this is about JS enabled. It's the same endpoint. Open dev console and have a look.
- segfaultbuserr 7y agoI can confirm. Just upvoted your comment with JavaScript enabled, still has 10 KiB transfer.
- manigandham 7y agoYou're correct that when JS is disabled, any interaction requires a HTTP request from a link or form, and that does a full page reload. However when JS and AJAX is used, it's expected that it also avoids an entire full-page HTML response that goes unused. It can easily be a 204 instead.
- jakeogh 7y agoCan't frame tags reload independently?
- manigandham 7y agoIt's still a full page refresh but with a page within a page. Making every comment a separate iframe would make the site very resource intensive on client and server.
- jakeogh 7y agoI dont see why it would be resource intensive server side. In fact, it would be less resource intensive, since we avoid a full page reload and instead reload a single comment iframe. As for the rendering engine, a iframe tag per comment is nothing compared to the pile of JS that's normally there on other sites.
- manigandham 7y agoEvery frame is still a full HTML document that needs to be generated even if it just contains a single comment. This page has 370+ comments which would mean 370+ additional HTTP requests to load them all as standalone HTML pages. That's a massive increase in server load. On the client, iframe tags are entirely separate browser windows and can use up considerable resources. It's like opening up hundreds of tabs and is far more intensive than running some javascript code which is quickly parsed, compiled and cached in modern JS engines.
- jakeogh 7y ago