7 ms·
Finally, voting without refresh
- pg 19y agoDon't worry, I'm not going to post a link about each releaselet. I just wanted to thank PB for helping us.
- kyro 19y agoWorks great and very snappy. Thanks.
- eposts 19y agoIs there no way to change your vote once you vote?
- ralph 19y agoI looked into how it worked and found other things out. Every page refers to /news.css. Since few HTTP headers are returned with /news.css, no caching is performed AFAICS anywhere between my browser and news.yc. So every page access makes the browser request /news.css again, doubling the number of hits. Any unknown URL returns a HTTP 200 OK instead of, e.g. a 404, e.g. http://news.ycombinator.com/standards_what_standards http://news.ycombinator.com/standards_what_standards . This is seen by my browser when it requests a /favicon.ico. It tries twice, presumably because it isn't keen on the HTML response. That's twice per page access to news.yc. It can't learn there's no favicon because it gets a 200 back rather than a 404. Sorting this out would just seem nice. Pretty trivial too, I'd have thought. At the moment every dynamic page access to view a thread is generating an extra three needless HTTP requests.
- ralph 19y agoOn a related note, http://news.ycombinator.com/news.css http://news.ycombinator.com/news.css returns a MIME type of text/html instead of text/css like it should. This causes warnings to appear in this browser's console.
- ralph 19y agoYeah, thanks PB. It's a big improvement and cuts down bandwidth use a lot too. I've peered at the Javascript and most of its obvious even without knowing Javascript :-) Might someone answer a few questions? node.href just returns an empty text/html document when fetched. Does this happen synchronously or not? What do browsers do when they're given text/html as the content of an image and what do the specs define they do? When is ping freed? Is it automatic when it goes out of scope and does that suggest that the image fetch is synchronous? I'm trying to understand what delays occur when and whether on a larger scale you'd need to manually free some of these resources.
- danielha 19y agoPrediction: this submission reaches the Top 10 after every visitor verifies the asynchronous voting. Great stuff, Pauls (and Trevor).
- phony_identity 19y agoIt's Robert. Trevor doesn't work on news.yc, I don't think.
- Elfan 19y ago"Thanks to Paul Buchheit for writing the Javascript, and Trevor Blackwell for help integrating it."
- codeLullaby 19y agoNice move! But one thing... The server should get updated first. Only after that should the UI value change. [Right now, its the reverse here.Is there any particular reason for such an implementation?]
- npk 19y agoIs there any particular reason for such an implementation? I think the answer boils down to this: http://paulbuchheit.blogspot.com/2007/06/wasting-time-on-things-that-really-dont.html http://paulbuchheit.blogspot.com/2007/06/wasting-time-on-things-that-really-dont.html (This is not meant to be a nasty sounding response.)
- paul 19y agoYeah, it seems to work ok for reddit (try "work offline" then click the arrows on reddit). For things that are really important (sending an email or something) I'd check the reply, but for arrow clicking it's probably not worth the effort and delay.
- codeLullaby 19y agoPaul can say this, but, {update the server first} - {return a value} - {update the UI} doesn't require much "effort".Its just a good practice. I am just suggesting Paul.
- philh 19y agoYou could always update the UI on the assumption that it will succeed, and then check the return value. If you get failure, notify the user somehow. Making the UI seem a slight bit more responsive might not be really worth it, of course.
- paul 19y agoUI latency is actually very important, and generally under-appreciated. Sometimes, it's better to be fast than perfect.
- palish 19y agoI'm curious why you're averse to learning and using javascript, Paul. It's really close to Lisp (no compile-time macros, but functions are first class objects, has lexical closures, so on). It's really a powerful language, much more so than C. (Not criticizing, just curious)
- pg 19y agoI'm not averse to using it. Just never got around to it till now.
- mynameishere 19y agoDoes it make the request, then update the number? Or does it update the number and make the request at its leisure?
- npk 19y agoWell, look at the code :) I did, it was educational. Node.href contains the values that are linked on the up/down arrows. // ping server var ping = new Image(); ping.src = node.href; return false; // cancel browser nav } The clever part is in using the image object as an ajax-like connection, response isn't check, and I'm not sure if it's async. Question: is this a common javascript idiom? Is it browser portable? Mynameishere: The answer to your question is it updates the number and makes an immediate request to the server.
- palish 19y agoEr.. So that means it's a GET request, and GET requests which modify state on a website are bad. Things like Google Web Accelerator silently visit all the links on the page and cache the result in case you decide to visit that link. So there might be some problems for people using those (For example, their accelerator might accidentally upvote all the comments in every comment page they visit)
- benhoyt 19y agoGoogle Web Accelerator won't follow the link, because it's got query parameters (a ? in the URL). See their help: http://webaccelerator.google.com/webmasterhelp.html#prefetch3 http://webaccelerator.google.com/webmasterhelp.html#prefetch3 It's just as well, too -- GETs are used so often for this kind of stuff that any web acceleration tool which ignored this would break lots of sites.
- ralph 19y agoGWA did use to follow all GETs, including those with parameters, and did cause all kinds of grief because of poorly written web sites, so they added the query parameter check to work around it.
- gyro_robo 19y agoWell, this explains why PG is so big on co-founders. The amount of AJAX needed is very little, and he still had two other people do it for him.
- pg 19y agoThe sw on the server is somewhat more complex. It takes some amount of knitting closures together to e.g. allow the submission of a link via the bookmarklet to work even when it has to be interrupted by a login.
- gyro_robo 19y agoOh sure, blame Arc.
- nirs 19y agoThe amount of AJAX is indeed very little, actually zero :-)
- gyro_robo 19y agoNeato, sans XMLHttpRequest.
- nirs 19y agoThere a stupid bug - after you vote, the arrow is hidden, but it will accept clicks :-) So you can continue to upvote many times, and the score text updates. When you refresh, the actual vote is restored. Tested with Safari 419.3.
- pg 19y agoI don't think I count this as a bug. If you do something stupid, you see something stupid, but it doesn't affect anyone else.
- deleted 19y ago[deleted]
- deleted 19y ago[deleted]
- aston 19y agoIt's not a harmful bug, but it's certainly not behavior users will appreciate. I could imagine a new user not understanding the one man, one vote property of the system, then being confused later when the votes seem not to have gone through. Adding the visual effect of idempotency on the frontend is probably a two-second fix, anyway.