Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dns-prefetch + preconnect vs. browser cache

To improve the page load time I want to use dns-prefetch and preconnect for external javascripts.

<link rel="dns-prefetch" href="https://example.com">
<link rel="preconnect" href="https://example.com">

What happen if the ressource (in my case the external javascript) is already in the browser cache? Do dns-prefetch and preconnect add page load time unnecessarily? In other words: Are dns-prefetch and preconnect only useful on the first page load?

like image 242
Sr. Schneider Avatar asked Apr 13 '26 21:04

Sr. Schneider


1 Answers

On the repeat visit, the preconnect/dns-prefetch will indeed be useless if all resources are taken from cache. But they will not increase page load time. They happen in parallel of page loading, and cache reads do not wait for DNS/TLC/TCP resolution. So the only drawback is that you create unused TCP connection and slightly increase the load on the server.

like image 97
jakub.g Avatar answered Apr 20 '26 14:04

jakub.g