Hacker News new | ask | show | jobs
by Town0 2051 days ago
What if on link hover, some javascript code notifies the server and the server pushes the page? When the user clicks the link the page will have already been downloaded. Would that not be possible and useful?
4 comments

“Notifying the server” is already done by browsers by just making a regular request. Prefetching links has been a thing for a while now. You don’t need HTTP/2 to do it.
This prefetching implementation is extremely simple fails gracefully. No complex browser APIs used to imitate a normal browsing experience. It all just works as it just goes through the caching system. I'd say this is nothing like existing prefetching implementations, which don't seem to be used much and no wonder.
This is a really weird system you have devised.

You are making a custom request to ask the server to push something to the browser.

Browser: POST /preload?url=/next-page Server: PUSH /next-page

Just cut out the middleman and make a regular request.

Browser: GET /next-page

Even better use browser preloading mechanisms so that the browser knows how to best prioritize them. In fact if you do it this way the browser can even start downloading subresources and prerendering the page.

From what i understand the push cache gets deleted the moment the http connection is closed, which to me makes it sound not the most suitable for this.

Maybe just adding a rel=preload link tag dynamically would be better (do link tags work dynamically? I have no idea). Or just fetching with normal ajax and use a service worker.

There are libraries [1] that achieve what you describe.

[1]: http://instantclick.io/ "InstantClick"

Yes, TurboLinks is another library that does this: https://github.com/turbolinks/turbolinks
Yes and I'd describe them as unpopular hacks. Http2 push is not a hack.
Actually... I've implemented both client and server side HTTP/2 push and I'd say... it's a hack and we should deprecate it and remove it from the spec.