14 comments

[ 3.0 ms ] story [ 47.6 ms ] thread
If you're using Firefox or a Chrome Beta, then you can view the `rel=preconnect` resource hint in use on my site https://www.lfgss.com/

You'll see it as a HTTP header:

    link:<//cdnjs.cloudflare.com>; rel=preconnect, <//www.google-analytics.com>; rel=preconnect, <https://login.persona.org>; rel=preconnect, <https://static.login.persona.org>; rel=preconnect, <//fonts.googleapis.com>; rel=preconnect, <https://fonts.gstatic.com>; rel=preconnect; crossorigin
It made a significant difference to Google Fonts speed as well as Persona.

I'd definitely recommend using resource hints in your base HTML template or server controller, for the assets that you know every page will access. This is the low hanging fruit... making this super specific for each page likely won't fit into your CMS easily.

But what if the browser already has all the page’s subresources in the network cache? Wouldn’t the preconnects then be a waste?
The browser can make sense of this, the browser can also make sense of not doing a DNS prefetch if it already has one in-flight for the preconnect, etc.

The gains are such that it is better to add the hints than not.

I'm wondering why W3C is using some limited declarative "language" instead of the more powerful Javascript to figure out these hints.
Sanity reasons, I suppose. One does not need to run a program in Turing-complete language just to express something as simple as few weighted sets.
Wow, Poe's Law strikes again. Are you making a joke or are you serious?
I wanted to make clear that I was serious, but there is no seriousness punctuation, only irony punctuation [1]

[1] https://en.wikipedia.org/wiki/Irony_punctuation

Well, then see drdaeman's response. There's no reason to add anything more which requires JavaScript unless there's absolutely no alternative.

Otherwise, why not just serve up a blank page which executes JavaScript to add characters one at a time?

Off-hand, I'd guess you can use these hints earlier in the loading process than you could start executing JS.
These hints can be placed inside the HTTP response header. A JavaScript API can only be used via `<script>`, which can only appear on the page (after the HTTP response has arrived).
> Additionally, the user agent MAY provide user setting to control the use of resource hints.

Why isn't this MUST? Users absolutely have to have a choice, because prefetching (even just DNS) allows tracking ("analytics") information to leak.

What's the best way to see that the browser does anything with this - does Chrome have visibility of this in the dev tool somewhere?
How does preconnect crossorigin=anonymous differ from a regular preconnect? (I'm guessing some http2 thing?)
The 'prefetch' relation exploit vector, coming soon to a browser near you.