How to use Cookie-Free Domains with Cloudflare in WordPress

cookies black

If you’ve analyzed your site via GTmetrix or Pingdom, you may have seen the error like “Use cookie-free domains”, especially if you’re using Cloudflare

cookie free domains

When you send a request to a URL (domain) it sends back the requested data along with some response headers. The response headers might also tell the browser to set a cookie. Cookies are used for various purposes like tracking, session (login), cart, comment etc.

If you’re using Cloudflare, they inject a cookie called “__cfduid“.

set cookie by cloudflare

Here is what GTmetix says:

Serve static content from a different domain to avoid unnecessary cookie traffic.

GTmetrix

It makes sense for using cookies for security, analytics and other features. However, due to Cloudflare’s reverse proxy approach, cookies are sent on static files too, which are unnecessary.

Will Cookies on Static Files Impact Performance?

As you noticed, only a single cookie is injected by Cloudflare which is only a few bytes. Even if you’ve 100 such requests, it won’t increase the size even by 1 KB.

So I would say, this is a false alarm from GTmetrix YSlow and you can safely ignore it.

Sad news, you can’t enable cookie-free domains in Cloudflare (unless you’re in Enterprise plan).

Here is what Cloudflare says:

Enterprise customers may request to disable the _cfduid cookie by contacting Cloudflare Support, but Cloudflare’s ability to detect and mitigate the impact of malicious visitors to a Customer’s website will be significantly impacted. While some speed recommendations suggest eliminating cookies for static resources, the performance implications are minimal

Cloudflare

Other Possible Solutions

As I said before, this won’t impact performance. But if you still want to score 100/100 in GTmetrix or Pingdom, use a CDN like BunnyCDN.

In BunnyCDN, it as simple as toggling a button:

cookie free domain in bunnycdn

Pricing of BunnyCDN is also very cheap. If your site has decent traffic, the cost will be <$10 per year.

Not just BunnyCDN, many other providers also have cookie-free domains.

Comment below if you’ve any queries or feedback. I read and reply back to each of them within 12 hours!

You May Also Like