This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

🔊 Web Growth Summit is here! Learn from industry experts on July 17-18, 2024. REGISTER NOW→

How to Fix “Serve Static Content From a Cookieless Domain” Warning

Updated on December 14, 2021

5 Min Read

We often test our WordPress site for speed and other performance related issues. Tools such as Pingdom and GTmetrix test the website and show detailed analysis highlighting any warnings and errors. “Serve static content from a cookieless domain” is one such warning which at times appear inside the performance insights table.

pingdom shows warning of Serve Static content

Serving static content such as JavaScript, CSS and image files do not need an HTTP cookie with it. These unnecessary cookies put extra load on network traffic and slow down the web page loading. Since it is no good with these cookies, speed testing tools shoot this warning so this type of content is served via cookieless domain to save precious server resources. So we will explore further what a cookieless domain is and what are other ways to avoid this warning.

Crush Errors Before They Crush Your Site (FREE WP Rescue Kit)

Site errors are like storms – frustrating visitors and hurting sales and SEO.️ With our FREE Ultimate Error-Fixing Checklist, you can diagnose errors, fix them fast and thrive!

Thank You

Your list is on it’s Way to Your Inbox.

However, there is one thing worth noting. It is safe to ignore this warning with Cloudways which uses new protocol HTTP/2 for data transferring. HTTP/2, unlike HTTP, is more efficient in handling concurrent requests hence is not affected by these small cookies.

Cloudways’ users can enable this feature via a 1-click button from their Server Dashboard → Settings and Packages.

enabling HTTP2

Let’s see how can we easily fix “Serve Static Content From a Cookieless Domain” warning in WordPress.

Fixing “Serve Static Content From a Cookieless Domain” Warning

In order to fix “Serve Static Content From a Cookieless Domain” warning, we will use two methods. Our first method is fairly easy and if you are lucky to be using Cloudways, then it’s only a matter of few clicks. Our second method, however, requires some knowledge and work but I can assure you whichever the method you are going to choose, I will make it as easy as possible. Let’s begin!

Method 1: Using a Content Delivery Network

Content Delivery Network or CDN for short is an effective way of serving static content to your end user. This network is spread across the globe and serve the cached content of your site from its nearest server to the user.

Introducing CDN to handle static content is an easier way. CDNs such as StackPath is capable of ignoring the cookies and can serve this content cookieless to the end user. Since no cookies are set by serving domain the warning goes away in the web testing tools.

Cloudways users can activate CloudwaysCDN powered by StackPath from their Application Dashboard simply by adding website URL.

enabling CloudwaysCDN

Method 2: Re-configuring WordPress Site

Another way of serving static content cookieless is by reconfiguring the WordPress site. This method involves the creation of either a subdomain in case you use a domain like www.mydomain.com or getting a new domain in case you use top-level domain such as mydomain.com.

Creating a Subdomain

Create a subdomain and name it whatever you like for example static.mydomain.com. If you are using cPanel then head over to DOMAINS section and click on subdomain option.

enabling subdomain

Enter the name of your new subdomain and click on CREATE button to save the changes.

creating subdomain

Cloudways users can create a subdomain using the application dashboard. Navigate to Domain Management tab and add additional domains.

domain management

Now point your subdomain to main domain via CNAME using DNS settings of your domain provider.

Next step will be to point this subdomain to the WordPress directory which is located inside the WordPress installation file in the public_html folder.

Add the code below in wp-config.php file which is also located inside the WordPress installation directory.

define(“WP_CONTENT_URL”, “http://static.mydomain.com”); 
define(“COOKIE_DOMAIN”, “mydomain.com”);

Update Existing Post Content

We have now configured our WordPress site to server static content from cookieless domain. But this will only be applicable for our future posts. In order to to update the existing posts simple open your database manager and navigate to tables. Open the query window and run the following command.

UPDATE wp_posts SET post_content = REPLACE(post_content,
 'http://www.mydomain.com/wp-content/uploads/','http://static.mydomain.com/uploads/')

Note: Replace ‘mydomain’ with your domain name.

Above query will update the existing posts so it does not generate the warning on the browsers. Now log in to your WordPress admin dashboard and check if the existing posts are loading their images from static.mydomain.com.

Google Analytics Settings

If your WordPress site used Google Analytics for tracking then you also have to make a few changes in the Analytics code and also make sure that the same settings are being used inside the Analytics account.

Inside the code change the the ‘auto’ property to your www.address of your website.

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXX-1', 'www.mydomain.com');
  ga('send', 'pageview');
  ga('set', 'displayFeaturesTask', null);

</script>

Now go to Google Analytics account and navigate to ‘Admin’ menu.

Under ‘Property Settings’ tab, make sure that both the Property Name and Default Property URL has your www address of your website.

How to Solve CloudFlare Cookies Problem?

CloudFlare CDN is a great service and is used by many WordPress sites. Due to its structure CloudFlare CDN adds a cookie _cfduid with every HTTP request. These cookies can not be avoided using any official method available except for not using CDN service and stick to its fast DNS service.

Let’s dig deep and explore alternate method to get rid of these cookies.

  1. 1 – Avoid using it as CDN service for domain/subdomain from which you intend to serve static content and use it just as a DNS manager.
  2. 2 – If you still wish to use CloudFlare and avoid its cookies then use another domain based hostname such as StackPath to server static content. Use another subdomain for it such as abc-stackpath.com

Using CloudFlare as DNS Manager Only

In order to use CloudFlare as a DNS manager only, log into its dashboard and switch the status to ‘Paused’. Now follow the image below to configure DNS record.

CloudFlare DNS Manager

Wait for DNS to get propagated and to confirm it check its status at whatsmydns.net

Final Thoughts

Today we explored the reason behind “Serve Static Content From a Cookieless Domain” warning and learned two methods to resolve this issue. CDN is a powerful utility which has tons of benefits in terms of website performance. Share your experience of implementing these two methods in the comments below.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Owais Khan

Owais works as a Marketing Manager at Cloudways (managed hosting platform) where he focuses on growth, demand generation, and strategic partnerships. With more than a decade of experience in digital marketing and B2B, Owais prefers to build systems that help teams achieve their full potential.

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now