# Do not use WP Rocket preconnect feature

- 2025-09-05
- 5 min read

Tags:

- [performance](/md/blog/tag/performance/)
- [wordpress](/md/blog/tag/wordpress/)

![wp-rocket-preconnect-with-crossorigin.png](/file/upload/img/blog/wp-rocket-preconnect-with-crossorigin.png?v=8895e84fe3e8)

update: this issue has been addressed in [WP Rocket release 3.20.1](https://github.com/wp-media/wp-rocket/releases/tag/v3.20.1) by moving to dns-prefetch. [New LinkedIn post covering this](https://www.linkedin.com/feed/update/urn:li:activity:7399754761060917248/).

One of the changes in WP Rocket 3.19 involves preconnecting to external domains:

> Preconnect to external domains is now fully automated and enabled by default, optimizing connections to third-party resources, individually for both desktop and mobile
> 
> [github.com/wp-media](https://github.com/wp-media/wp-rocket/releases/tag/v3.19)

And I've already spotted this behavior on multiple WordPress sites. One of them, a WooCommerce shop showed 15 preconnects injected by WP Rocket.

In theory, this sounds like a good idea. But in reality, it is not.

## WP Rocket behavior

According to their [article covering their preconnect behavior](https://docs.wp-rocket.me/article/1869-preconnect-to-external-domains), WP Rocket automatically enables this optimization upon activation. So, once upgrading to WP Rocket v13.9, this comes out of the box. You don't even have to specify which domains your site should preconnect to. That sounds very convenient.

While the WP Rocket designed this enhancement thinking it improves the loading times of websites using WP Rocket, it is actually more likely to result in sitespeed regressions.

## Multiple issues with this implementation

### The \`crossorigin\` attribute is misplaced

The `crossorigin` should only be used when you're actually making cross-origin requests that need credentials or when you want to ensure CORS compliance. For many external domains like social media, analytics scripts, or CDNs, adding `crossorigin` unnecessarily will actually:

- Result in a DNS lookup that will be re-used by the browser, but it's the TCP/TLS handshakes that can't be reused
- When an actual resource from the same domain is loaded in a non-CORS way, it results in yet another TCP + TLS/HTTPS handshake
- Resulting in unnecessary work and overhead by the browser

For example, [https://fonts.gstatic.com/](https://fonts.gstatic.com/) serves webfonts `crossorigin` and does need the attribute, but [https://fonts.googleapis.com/](https://fonts.googleapis.com/) does not as that hostname only serves CSS. This conclusion can also be drawn when looking at the preconnects that will be suggested by Google Fonts embed code:

```
<link rel="preconnect" href="https://fonts.googleapis.com/">
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
```

Additional notes:

- I wrote about [preconnect and crossorigin](/md/blog/spot-issues-in-preconnect-code-snippet-how-to/) before as it's easy to misunderstand its purpose and implementing it incorrectly.
- [Self-hosting web-fonts](/md/blog/should-you-preload-fonts-for-performance/#self-host-web) is better for both performance and privacy

### Too many preconnects

This WP Rocket feature is likely to preconnect to too many hostnames (i.e. too eager) depending on the amount of external resources on your site. This can be problematic as:

- Each preconnect uses up browser connection limits
- Preconnecting to domains you rarely use wastes resources
- It can actually slow down connections to domains you frequently use
- Mobile devices especially benefit from more selective preconnecting

### Privacy / GDPR risk

The privacy risk could create significant legal problems depending on local privacy regulations. It can put merchants (especially those in Austria + Germany) in extra risk, but similar concerns apply globally under regulations like CCPA, PIPEDA, and other data protection laws:

- By default, user IP addresses get logged by servers
- By preconnecting to them, IP addresses will already be shared even before any consent is given
- This violates GDPR's "consent before processing" principle for personal data and similar requirements in other jurisdictions, and may unknowingly create liability for website owners using WP Rocket

This is especially problematic because many WP Rocket users might not realize they're now automatically violating privacy regulations, particularly if they're using cookie consent banners that are supposed to prevent third-party data sharing until users explicitly agree.

Just doing a domain name lookup (`rel="dns-prefetch"`) instead of preconnecting (`rel="preconnect"`) doesn't come with this risk.

## Check your own site

A person replied to my LinkedIn post and said the following:

> I also believed that pre-connecting all third-party URLs would increase the speed. But when I tried to execute it, I found that the speed was getting slower

In other words, it can actually regress the sitespeed as experienced by real users. When you're using detailed [Real User Monitoring tool to monitor sitespeed and Core Web Vitals](https://www.rumvision.com/), you should be able to determine if your visitors are affected by looking at the First Contentful Paint (FCP) metric of uncached pagehits. Be sure to focus on the 95th (or surrounding) percentiles across mobile navigations.

If you're not using a RUM tool, there's a way to see if your site is technically affected:

- Navigate to your site
- Open its the source code (`Control+U` on Windows desktop)
- Search for `data-rocket-preconnect` (Control+F on Windows desktop and typing or pasting this in the searchbox)
- If there are results, check if those  elements include the `crossorigin` attribute

If so, then your site is using WP Rocket 13.9 or newer. If not, then your either not using WP Rocket, using an older version or using a newer version where it's fixed already.

## The fix

### Fix for site owners

If you're using WP Rocket 13.9 or newer, I recommend disabling this feature or switching it to `dns-prefetch` instead. Their article covers both options:

1. [disabling its preconnect behavior](https://docs.wp-rocket.me/article/1869-preconnect-to-external-domains#how-to-deactivate-this-feature)
2. [switching to dns-prefetch](https://docs.wp-rocket.me/article/1869-preconnect-to-external-domains#prefetch-dns-requests)

### Fix by WP Rocket

Meanwhile, [I created a issue/ticket](https://github.com/wp-media/wp-rocket/issues/7612) over at the WP Rocket repo to get it addressed and improved at the source. Possible fixes could be:

1. Using `dns-prefetch` by default and allowing site owners to switch to `preconnect` per domain in an admin UI;
2. And/or then only add the `crossorigin` attribute by matching a domain with a internally maintained list of domains that does typically require the `crossorigin` attribute

*\* Update*: A WP Media team member involved with WP Rocket already [replied on my LinkedIn post](https://www.linkedin.com/feed/update/urn:li:activity:7369636047913263106?commentUrn=urn%3Ali%3Acomment%3A%28activity%3A7369636047913263106%2C7369677647179685888%29&dashCommentUrn=urn%3Ali%3Afsd_comment%3A%287369677647179685888%2Curn%3Ali%3Aactivity%3A7369636047913263106%29), suggesting the same fixed and indicating that they are on top of it (actually already [became a milestone for version 3.20.1](https://github.com/wp-media/wp-rocket/milestone/218)) :)

## Read next

- ![open-love-letter.jpg](/file/upload/img/blog/open-love-letter.jpg?v=b4ab76b635fb)
  ### [Improving WordPress performance: an open letter](/md/blog/improving-wordpress-performance-an-open-letter/)
  3 January 2022
- ![jquery-wordpress.png](/file/upload/img/blog/jquery-wordpress.png?v=d977fbbde6c0)
  ### [Why Wordpress is not correct to blame jQuery for bad pagespeed](/md/blog/why-wordpress-is-not-correct-to-blame-jquery-for-bad-pagespeed/)
  7 December 2021
- ![wordpress-mobile-accessibility.jpg](/file/upload/img/blog/wordpress-mobile-accessibility.jpg?v=89c287c83d44)
  ### [Wordpress is lacking behind and starts a performance team](/md/blog/wordpress-is-lacking-behind-and-starts-a-performance-team/)
  29 October 2021
