Wordpress Read Cookie From Another Domain That I Own

Serve Static Content From a Cookieless Domain

Nosotros ofttimes test our WordPress site for speed and other functioning related problems. Tools such as Pingdom and GTmetrix exam the website and bear witness detailed analysis highlighting whatsoever warnings and errors. "Serve static content from a cookieless domain" is 1 such warning which at times appear inside the operation insights table.

pingdom shows warning of Serve Static content

Serving static content such as JavaScript, CSS and image files practice non 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 resource. So we will explore further what a cookieless domain is and what are other ways to avoid this warning.

Even so, there is i thing worth noting. It is safe to ignore this warning with Cloudways which uses new protocol HTTP/two for data transferring. HTTP/2, different HTTP, is more efficient in handling concurrent requests hence is not afflicted by these small cookies.

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

enabling HTTP2

Allow's see how can nosotros easily fix "Serve Static Content From a Cookieless Domain" warning in WordPress.

Fixing "Serve Static Content From a Cookieless Domain" Alert

In gild to set up "Serve Static Content From a Cookieless Domain" alert, we will apply two methods. Our first method is fairly easy and if yous are lucky to be using Cloudways, then information technology's only a matter of few clicks. Our 2nd method, nonetheless, requires some cognition and piece of work just I can assure you whichever the method you are going to cull, I will make information technology as easy as possible. Let's begin!

Method 1: Using a Content Commitment Network

Content Delivery Network or CDN for short is an constructive way of serving static content to your cease 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 fashion. CDNs such equally StackPath is capable of ignoring the cookies and can serve this content cookieless to the stop user. Since no cookies are gear up by serving domain the warning goes away in the web testing tools.

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

enabling CloudwaysCDN

Method 2: Re-configuring WordPress Site

Another manner of serving static content cookieless is past reconfiguring the WordPress site. This method involves the cosmos of either a subdomain in case you utilize a domain like world wide web.mydomain.com or getting a new domain in case y'all use height-level domain such as mydomain.com.

Creating a Subdomain

Create a subdomain and name it whatsoever you lot like for case static.mydomain.com. If you are using cPanel then head over to DOMAINS department and click on subdomain selection.

enabling subdomain

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

creating subdomain

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

domain management

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

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

Add together the code beneath 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 take now configured our WordPress site to server static content from cookieless domain. But this volition simply exist applicable for our time to come posts. In gild to to update the existing posts elementary open up your database director and navigate to tables. Open the query window and run the following command.

UPDATE wp_posts SET post_content = Supercede(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 non 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 take to make a few changes in the Analytics code and likewise make sure that the aforementioned settings are being used inside the Analytics business relationship.

Inside the code modify the the 'auto' property to your www.accost of your website.

<script>   (role(i,s,o,one thousand,r,a,thou){i['GoogleAnalyticsObject']=r;i[r]=i[r]||part(){   (i[r].q=i[r].q||[]).button(arguments)},i[r].50=1*new Date();a=south.createElement(o),   m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,grand)   })(window,document,'script','//world wide web.google-analytics.com/analytics.js','ga');    ga('create', 'UA-XXXXXXX-ane', 'www.mydomain.com');   ga('send', 'pageview');   ga('set', 'displayFeaturesTask', null);  </script>

Now go to Google Analytics account and navigate to 'Admin' bill of fare.

Under 'Property Settings' tab, make certain that both the Property Proper name and Default Property URL has your world wide web 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. ane – Avoid using it every bit CDN service for domain/subdomain from which you intend to serve static content and utilise information technology just equally a DNS manager.
  2. 2 – If you still wish to use CloudFlare and avert its cookies then utilize another domain based hostname such every bit StackPath to server static content. Use some other subdomain for it such as abc-stackpath.com

Using CloudFlare as DNS Manager Just

In order to employ CloudFlare as a DNS managing director 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.cyberspace

Concluding Thoughts

Today we explored the reason behind "Serve Static Content From a Cookieless Domain" alert and learned two methods to resolve this consequence. 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

Customer Review at

"Beautifully optimized hosting for WordPress and Magento"

Arda Burak [Agency Owner]

Ibad Ur Rehman

Ibad Ur Rehman is a WordPress Community Manager at Cloudways. He likes to explore the latest open up-source technologies and to interact with different communities. In his free time, he likes to read, watch a series or fly his favorite Cessna 172SP in X Airplane 11 flight simulator.

Wordpress Read Cookie From Another Domain That I Own

Source: https://www.cloudways.com/blog/serve-static-content-from-a-cookieless-domain/

0 Response to "Wordpress Read Cookie From Another Domain That I Own"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel