# Who is driving dns-prefetch adoption?

**URL:** <https://discuss.httparchive.org/t/who-is-driving-dns-prefetch-adoption/2263>\
**Category:** Analysis\
**Created:** [November 11, 2021, 10:01pm UTC](https://discuss.httparchive.org/t/who-is-driving-dns-prefetch-adoption/2263 "2021-11-11T22:01:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rviscomi](https://yyz1.discourse-cdn.com/flex035/user_avatar/discuss.httparchive.org/rviscomi/32/835_2.png) [@rviscomi](https://discuss.httparchive.org/u/rviscomi)\
**Post date:** [November 11, 2021, 10:01pm UTC](https://discuss.httparchive.org/t/who-is-driving-dns-prefetch-adoption/2263/1 "2021-11-11T22:01:46Z")

</div>

Posing a challenge to all the data analysts in the room 🤠

In the 2021 Resource Hints chapter of the Web Almanac (coming soon!) author @imkevdev says:

> The most widely used resource hint is dns-prefetch (36.4% on mobile); which is unsurprising, considering it was introduced in 2009. With the widespread use of HTTPS, in many cases it should be replaced with preconnect (12.7% on mobile).

If true, this sounds like a good opportunity to identify who is driving `dns-prefetch` adoption and try to improve the ecosystem by encouraging them to use the `preconnect` hint instead.

---

<div class="post-metadata">

**Author:** ![tunetheweb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discuss.httparchive.org/tunetheweb/32/1671_2.png) [@tunetheweb](https://discuss.httparchive.org/u/tunetheweb)\
**Post date:** [November 11, 2021, 10:18pm UTC](https://discuss.httparchive.org/t/who-is-driving-dns-prefetch-adoption/2263/2 "2021-11-11T22:18:43Z")

</div>

Would be interesting to see some analysis on this. However he does say “in many cases” for good reason.

DNS look-ups are cheap.

Preconnects are more expensive due to HTTPS certificates using up bandwidth (not to mention the chatiness needed to look up DNS, TCP, and HTTPS). Small in grand scheme of this but at critical initial loading time “small” can make a big difference.

But still would be good to dig into it with that in mind…

---

<div class="post-metadata">

**Author:** ![malchata](https://yyz1.discourse-cdn.com/flex035/user_avatar/discuss.httparchive.org/malchata/32/1567_2.png) [@malchata](https://discuss.httparchive.org/u/malchata)\
**Post date:** [November 11, 2021, 10:34pm UTC](https://discuss.httparchive.org/t/who-is-driving-dns-prefetch-adoption/2263/3 "2021-11-11T22:34:19Z")

</div>

Seconded on the expensiveness of preconnects. DNS prefetches are low cost, and will probably hit some DNS caching layer somewhere (sometimes even in a local network’s router). I think encouraging preconnect over dns-prefetch could also have the unintended side-effect of encouraging developers to use expensive preconnects that could go to waste in scenarios where a resource from the target origin never gets used.

---

<div class="post-metadata">

**Author:** ![imkevdev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discuss.httparchive.org/imkevdev/32/1941_2.png) [@imkevdev](https://discuss.httparchive.org/u/imkevdev)\
**Post date:** [November 12, 2021, 8:21am UTC](https://discuss.httparchive.org/t/who-is-driving-dns-prefetch-adoption/2263/4 "2021-11-12T08:21:17Z")

</div>

Looking at the domains which contribute mostly towards dns-prefetch usage, Wordpress is the biggest contributor. I think by default Wordpress includes the snippet. \*

```sql
<link rel=dns-prefetch href='//s.w.org'/>

```

or

```sql
<link rel=dns-prefetch href='//s0.wp.com'/>
<link rel=dns-prefetch href='//wordpress.com'/>

```

There is no `preconnect` hint by default on Wordpress sites. (please correct me if mistaken).

The next most popular domain is related to Google Fonts. Google Fonts now (couldn’t find a date when this changed) recommends `preconnect`.

| client | host | freq | total | pct |
| --- | --- | --- | --- | --- |
| mobile | [s.w.org](http://s.w.org) | 1888032 | 9575451 | 19.72% |
| mobile | [fonts.googleapis.com](http://fonts.googleapis.com) | 1344386 | 9575451 | 14.04% |
| mobile | [www.google.com](http://www.google.com) | 261441 | 9575451 | 2.73% |
| mobile | [ajax.googleapis.com](http://ajax.googleapis.com) | 211449 | 9575451 | 2.21% |
| mobile | [monorail-edge.shopifysvc.com](http://monorail-edge.shopifysvc.com) | 190904 | 9575451 | 1.99% |
| mobile | [www.googletagmanager.com](http://www.googletagmanager.com) | 181711 | 9575451 | 1.90% |
| mobile | [s0.wp.com](http://s0.wp.com) | 162677 | 9575451 | 1.70% |
| mobile | [cdnjs.cloudflare.com](http://cdnjs.cloudflare.com) | 151468 | 9575451 | 1.58% |

**Query:**

```sql
#standardSQL
# Most popular hosts users dns-prefetch to
# capped to one hit per url to avoid having the results skewed by websites which dns-prefetch many resources from the same host

CREATE TEMPORARY FUNCTION getResourceHintsHrefs(payload STRING, hint STRING)
RETURNS ARRAY<STRING>
LANGUAGE js AS '''
try {
  var $ = JSON.parse(payload);
  var almanac = JSON.parse($._almanac);
  return almanac['link-nodes'].nodes.filter(link => link.rel.toLowerCase() == hint).map(n => n.href);
} catch (e) {  
  return [];
}
''' ;

SELECT
  client,
  host,
  freq,
  total,
  pct
FROM (
    SELECT
      client,
      host,
      COUNT(0) AS freq,
      SUM(COUNT(0)) OVER (PARTITION BY client) AS total,
      COUNT(0) / SUM(COUNT(0)) OVER (PARTITION BY client) AS pct,
      ROW_NUMBER() OVER (PARTITION BY client ORDER BY COUNT(0) DESC) AS pos
    FROM (
      SELECT
        client,
        url,
        host
      FROM (
          SELECT
            _TABLE_SUFFIX AS client,
            url,
            NET.HOST(href) AS host
          FROM
            `httparchive.pages.2021_07_01_*`,
            UNNEST(getResourceHintsHrefs(payload, "dns-prefetch")) AS href
        )
      GROUP BY
        client,
        url,
        host
    )
    GROUP BY
      client,
      host
    ORDER BY
      client,
      freq DESC
)
WHERE pos <= 100

```

When looking at the numbers, keep in mind that Wordpress makes up around 25% of origins in HA.

**EDIT (2021-11-12)**: \* The [s.w.org](http://s.w.org) domain is the CDN for serving emoji SVG images (provided by Twemoji) when WordPress detects (via its inlined emoji-loader.js) that the browser doesn’t support native emoji characters. This CDN has been used since WordPress 4.6. [Source](https://github.com/HTTPArchive/almanac.httparchive.org/pull/2452/files/fc2c0ae4324aa6772c760e2f7b4e10135c9782ac..3472db767b60a262e64212e7ab923be56d28ccf6#r748463389)
