Lurker News
http://instantclick.io/

It seems the internet architecture won't bring us instant websites anytime soon. So here is a hack.
I released this JS library last month (today is version 2.0 release, fixing v1.0's rough edges), it makes use of HTML5's pushState and preloading to make a website instant.
It works like this: before clicking on a link, you'll hover over it. And there's a delay of 200-300 ms between these two events. InstantClick uses this delay to preload a page, when you click on a link it will display instantly in most case. (You can test on the website.)
That's similar to pjax and Turbolinks, for it uses HTML5's pushState and Ajax. And preloading is thrown into the mix.
In case preloading all the links that a user hover over is too much work for the server, there's also an option to set a delay before preloading kicks in, or to preload on "mousedown". Mousedown is when you press your mouse button (a click is when you release it). This way you still get a slight "magical" speed advantage, and pjax's benefits (notably, no recalculation of scripts/styles on every page change).
For mobile it preloads on touchstart, so you get 400 ms to preload. This is different from FastClick: with InstantClick a user can still double tap to zoom without triggering a link.
As said in the first sentence, the internet architecture can't bring us instant websites today or tomorrow. So I think this — InstantClick — could be a pretty big thing to improve the situation at scale.
The main challenge I see is that existing JS scripts may not work with it out of the box. I don't do much web development nowadays though, so I don't know how big of a problem that is, and I don't know if there isn't any other major barrier in the way to make this mainstream.
That's why I'm awaiting your opinion, smart folks of HN.

Comments (174) 47 threads

VeejayRampay6 replies#
Another idea: take into account the movement of the mouse to define a directional cone in the general direction of the movement, which would enable you to preload your pages even before the hover state occurs.
dieulot2 replies#
Kinda overkill. ;) I may explore this idea later, but I don’t have great hope for it.
ivanca2 replies#
Most times there are some few links that are very frequently clicked on; for example in Hacker News is usually the "next page" and the "threads". So if there is not one already there should be a way to specify some (obligatory?) preload pages.
dieulot#
In my opinion even that is overkill. Remember, in most cases it’s already instant. The return on investment (speed/requests) abruptly declines with brute preloading.
CoryG892 replies#
I think you should utilize the prefetch behavior of the link tag for situations such as these. No need for JavaScript at all.

Continue this thread — 2 replies

VeejayRampay#
It is overkill, you're absolutely right about that. But that's the good thing about the webs, you can throw the stupidest ideas on the table and the let everyone flesh it out :D
agumonkey#
Weird I thought about this last night and wondered if browser pruned the dom/layers based on input device deltas.
Vektorweg3 replies#
Or just load every page. ;)
yogo1 reply#
That might not be very nice for some mobile users that are on a site with a ton of links (like a news site) :)
hakcermani1 reply#
There is no hover for mobile. Maybe track eye focus in future :-)

Continue this thread — 1 reply

dhoulb1 reply#
Not a bad shout. Not EVERY page, but if you have a five page site, you might as well pull in all five at the time, and save the other four requests later.

The actual HTML is only going to add another few KB.

dclara#
I'm sorry that I don't feel it very efficient, because sites with dynamic contents like HK or eCommerce/financial sites, very page is different from minute to minute.

But caching the skeleton of the page will work. We need browser to do it for us, just like browsers already caches the images.

baddox#
Or the pages that are most likely to be requested, based on previous session data which you have stored and analyzed.
yelnatz#
This article was really eye opening when I read it a few months ago.

I've always hated menu dropdowns where it would close if you try to skip to the next submenu you've opened, since you hovered on the other parts on your way to the submenu.
So you'd end up having to perfectly 'trace' the menu so it won't close down on you.

joshuahhh1 reply#
That article says nothing about preloading pages. The speed gains are purely a UI thing -- if you're clever about keeping submenus open even when the mouse leaves the submenu's entry in the main menu, you don't need to provide a delay for menu opening/closing.
dmethvin#
I think the Amazon example was being used as an example of the "directional cone", not preloading.
mcpherrinm#
A few years ago, I went to a tech demo/hackathon thing. Somebody had some neat experiments with preloading pages speculatively based on user behaviour

The coolest approach given was when a user types in the search box, kick off the request for the full results page if they move their mouse on a motion curve towards one of the results, with some machine learned data on how people move their mouse: Not quite in a straight line, and with some acceleration.

zarex#
I believe I read somewhere that Amazon does this for their menus. Clever idea to utilize this kind of analysis though.

edit: @devgutt else already mentioned this. I had this page open for a while before posting.

fiatjaf#
Another idea: preload all links of every page.
CoryG891 reply#
After looking at the source, one thought I have is that since you are dealing with such small timescales you should use the high resolution window.performance.now function (or the Date.now function for higher compatibility) as a timer instead of using the Date object as you do.
dieulot#
Thanks, I’ll look into it.
callesgg2 replies#
Realy Cool, Only real problem with this is if the clicking has side effects like: http://example.com/?action=logout as brought up on page.

And probably a ton of other application bugs as style and script stuff wont load. like they normally would

dieulot1 reply#
You can blacklist these links (or whitelist all the other links).
mrfusion1 reply#
Would it be worth blacklisting logout by default?

Maybe blacklist any links with the words logout, delete, etc anywhere inside the a tag or in the attributes?

dieulot1 reply#
No, my philosophy is to not do anything that could get into one’s way. And that’s a false sense of security.

If one is worried about preloading links that triggers an action, there is a whitelist mode to enable links as you review them.

Continue this thread — 1 reply

dylz3 replies#
Modifying session state should be a POST, not a GET.
callesgg#
It is more than often not. Google mail is one example.

But i do concur.

yogo3 replies#
In theory yes, but I'd wager that most of the time logouts are just hyperlink (/account/signout, /logout, etc.). Unless you had a good reason to, you kinda have to go out of your way to make it a POST.
ecesena3 replies#
From a security point of view this is not good. An attacker can embed the logout link wherever (e.g. send a tweet) and logout your users. As said in the parent post, GETs should be idempotent and, in particular, not change any state.

Continue this thread — 3 replies

adambard#
I feel using a library like this would constitute a good reason.
windsurfer13 replies#
So you're saying that poorly-designed applications wouldn't work properly sometimes.

Continue this thread — 13 replies

nimish3 replies#
It ought to be a PUT since it's idempotent but still modifies state.

It definitely should not be a GET, since good practice says that GET is idempotent (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html)
Nobody ever follows this since we all want stuff like www.example.com/articles/latest to respond to GET and also have different content depending on time. The distinction is at the core of the REST abstraction and it's an art.

StavrosK1 reply#
It clearly says that GET's side effects should be the same every time it's run. It doesn't say data retrieved by GET can never, ever change.

Continue this thread — 1 reply

michaelmior1 reply#
Curious where you get the rationale that idempotent state updates should be PUT requests and not POST.

Continue this thread — 1 reply

derefr4 replies#
Oh, are we talking HATEOAS session support?

    # if you don't have a session token yet
    POST /session-tokens # Accept: application/json
      => 200 {"token": "someuuid"}

    # no cookies set!
    # stuff the session token in localStorage instead

    # now use it
    PUT /sessions/someuuid # with your login details
      => 201

    GET /sessions/someuuid/inbox # Accept: application/json
      => 200 {...}

    GET /sessions/someuuid/inbox # again
      => 304 # wow much cached

    # meanwhile
    GET /sessions/otheruuid/inbox
      => 200 {...} # other user: other memcached prefix!

    # pages that won't change per-user...
    GET /home
      => 304 # can be cached globally
             # (use JS client-side, not edge-side, includes)

    # and finally...
    DELETE /sessions/someuuid
      => 301 /home # log out!
Basically, a session is just another resource that you create and then manipulate using its sub-resources. This makes all sorts of things easier: creating session tokens and attaching sessions to them (by logging in, or as a guest) are separate steps, so you can throttle logins at the just by throttling access to the token generator. No cookies and no ESI means caching (reverse-)proxies can actually cache. (Note that I'm presuming TLS and hygienic CORS here, so "session stealing" isn't a valid complaint. Or rather, without those things, it's just as valid a complaint for a cookie-based approach.)

Oh, but as a postscript, one little HATEOAS bonus tweak:

    POST /session-tokens
      => 200 {"token": "/sessions/someuuid"} # no constructing URIs!

Continue this thread — 4 replies

Load more comments