Preconnect all the things!.. sure?

Hi!

I’ve a dilema about the preconnect resource hint header.

The “preconnect all the things” approach means that i’m going to warm up every domain i will use in the current page load, that it’s good because as far i know Chrome keeps the connection open to that wormed up domain for 60 seconds or something like that. The risk here (i think) it’s to collapse the mobile connections right? to do too many things at the beginning… and also to increase the size of the initial http request header…

The other approach is to preconnect only the domains that affects the critical rendering path, here the page total load time will be increased because the following domains are not going to be warmed up.

I did some test but i’ve no RUM so they are synthetic tests that can misslead the conclusions, also the results are a little weird. I left the two screenshots attached.

What do you think it’s the best approach?

Thanks!

Hey Dario -

Good questions, I’ve wondered the same myself, which has led me to testing them. Honestly in all my efforts, I’ve failed to come up with a significant difference in overall page load speed by including/excluding the preconnect directive.

Granted, everyone’s site is different, and testing (I think testing synthetically is fine for this situation, just make sure it’s a consistent environment) is the best way for you to know in your own scenario.

I think common advice is it doesn’t hurt anything to include a preconnect directive for your CDN, or anything that’s referenced above the fold. But I wouldn’t worry about listing every single domain that’s used.

If I were you I’d focus on some other optimizations, such as your TTFB and blocking js.

yeap, i asked this same thing to Ilya Grigorik yesterday, this was his answer:

Also doing some deep internet search i cross along this thread were this is being discuss:

https://github.com/GoogleChrome/lighthouse/issues/3106

I will revert today the preconnect all the things approach today, only will left our own CDN domains, i now believe that only preconnect only the domains that affect the CRP and the above the fold content it’s the best approach :slight_smile:

I have seen improvements of > 1s by preconnecting to the domains that take a long time to establish SSL connections.

However, I also worry about putting a bottleneck in the mobile connections. That said, these are the ones going to benefit the most with preconnect IMHO.

That github issues link is super interesting. For those that don’t have time to read it, my takeaway is that you shouldn’t list more than 5 preconnects. And you should prioritize those 5 based on looking at your waterfalls and seeing which hosts really do need the speedup in connection setup.

Good find, thanks for bringing this up!