Finally, voting without refresh
ycombinator.com
ycombinator.com
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.
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.
Great stuff, Pauls (and Trevor).
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.)
It probably doesn't matter much for a site like this, but it's one of those things that's just a good habit to get into. Perform validations first, then actions, then UI updates. And do the actions that are most reversible or most likely to fail first. If you have a POST that updates a DB table and sends an e-mail, update the database first, because there's no way to unsend that e-mail.
It's like comparing constants from the left in C or doing "literal".equals(var) in Java - each individual occurrence is trivial, but taken together, it can save you a lot of grief.
Edit: though looking at the source, it's done through an Image update. I don't think there's any way to trap failure with that implementation, so here, it really doesn't matter.
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.
{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.
I guess if one was really concerned, you could update the UI immediately like News.YC does, and then change it back or show an error if it does happen to come back failed.
(Not criticizing, just curious)
Tested with Safari 419.3.
Adding the visual effect of idempotency on the frontend is probably a two-second fix, anyway.
// 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.
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?)
Arbitrarily performing GETs is something condoned by the HTTP 1.1 specification. Anything that assumes that GETs won't be arbitrarily followed is clueless.
You'd think people would have learned this the first time around. Don't write out-of-spec code and then complain when conforming code comes along and trashes your app. It's your bug, not theirs.
> GWA needs all kinds of heuristics to avoid that kind of thing.
How reliable. Wouldn't it be better to follow the spec so this kind of guesswork wasn't necessary?
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.