

Finally, voting without refresh - pg
http://ycombinator.com/newsnews.html#12jun07

======
pg
Don't worry, I'm not going to post a link about each releaselet. I just wanted
to thank PB for helping us.

~~~
ralph
I 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> . 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
On a related note, <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.

------
danielha
Prediction: this submission reaches the Top 10 after every visitor verifies
the asynchronous voting.

Great stuff, Pauls (and Trevor).

~~~
phony_identity
It's Robert. Trevor doesn't work on news.yc, I don't think.

~~~
Elfan
"Thanks to Paul Buchheit for writing the Javascript, and Trevor Blackwell for
help integrating it."

------
codeLullaby
Nice 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
Is 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>

(This is not meant to be a nasty sounding response.)

~~~
paul
Yeah, 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
Paul 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
You 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
UI latency is actually very important, and generally under-appreciated.
Sometimes, it's better to be fast than perfect.

~~~
aston
I think the standard solution here would be not to lie to the user. A quick
_sending_ graphic, which is replaced with a _received_ graphic would
accurately portray the events that are happening. These could easily be
iconic, maybe just a differently colored arrow while sending, which fades out
when it's sent.

------
palish
I'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
I'm not averse to using it. Just never got around to it till now.

------
nirs
There 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
I 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.

~~~
aston
It'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.

------
gyro_robo
Well, 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
The 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
Oh sure, blame Arc.

------
mynameishere
Does it make the request, then update the number? Or does it update the number
and make the request at its leisure?

~~~
npk
Well, 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
Er.. 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)

~~~
paul
It's just an adaptation of the old, non-js html, in which the arrows were just
links, and it's written such that it will work in the old way if the js
doesn't work for some reason (like I never bothered to test it with all the
browsers).

Anything that assumes that GET links can be arbitrarily followed will break
stuff all over the web. GWA needs all kinds of heuristics to avoid that kind
of thing. (maybe they avoid sending cookies or session ids?)

~~~
palish
Except it's vulnerable to an iframe exploit. See:
<http://news.ycombinator.com/item?id=27615>

~~~
paul
False (that GET causes the problem), see
<http://news.ycombinator.com/item?id=27629>

