{"id":61837,"date":"2021-08-25T12:31:19","date_gmt":"2021-08-25T17:31:19","guid":{"rendered":"https:\/\/blog.cpanel.com\/?p=61837"},"modified":"2021-08-25T12:31:19","modified_gmt":"2021-08-25T17:31:19","slug":"how-to-use-cookie-free-domains-for-faster-website-performance","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/","title":{"rendered":"How To Use Cookie-Free Domains for Faster Website Performance"},"content":{"rendered":"\n

Cookies are how websites remember. Without them, they forget you as soon as a page finishes loading. This ability to remember allows you to log in to a content management system or put products in an ecommerce shopping cart. It\u2019s what allows a dynamic CMS like WordPress to personalize web pages. But sites don\u2019t need to include a cookie with every file they serve, and needless cookies increase latency and generate unnecessary network traffic. <\/p>\n\n\n\n

Cookie-free domains let you separate content that needs a cookie from content that doesn\u2019t, ensuring that your site only serves cookies when it needs to. In this article, we explain how to set up and use a cookie-free domain. We use WordPress as an example, but a similar process works with other content management systems and ecommerce stores.<\/p>\n\n\n\n

What Is an HTTP Cookie?<\/strong><\/h2>\n\n\n\n

An HTTP cookie is a small piece of data a site sends to a web browser when it first loads a page. The cookie contains a unique identifier the browser stores alongside other information about the site. When the browser loads another page, it sends the identifier with the HTTP request. In this way, the site knows when a series of requests come from the same browser.<\/p>\n\n\n\n

When logging in to a website, you authenticate with a username and password. If you enter the right credentials, the site sets a cookie so you don\u2019t have to re-enter your credentials every time you load a page. This process is called session management; a series of otherwise independent requests are linked to a session by the cookie.<\/p>\n\n\n\n

This ability to remember is used in other ways too. The site can send personalized content unique to each visitor; an ecommerce store can, for example, display your recent orders because the cookie links an HTTP request to order data associated with your account in the site\u2019s database. In a more controversial application, advertisers use cookies to track you; they set a cookie, and advertising code across the web uses it to build a profile of the products you might be interested in.<\/p>\n\n\n\n

Why Use Cookie-Free Domains?<\/strong><\/h2>\n\n\n\n

The web needs cookies, but that doesn\u2019t mean every HTTP request does. For example, when you open a page with embedded images, each one triggers an HTTP request. But images don\u2019t change depending on who loads them, so serving a cookie is a waste of bandwidth. You may want to load different images for different users, but that\u2019s handled in the web page\u2019s HTML. The page needs a cookie; the images don\u2019t.<\/p>\n\n\n\n

The same is true of other static assets such as JavaScript code and CSS. A page might load dozens or even hundreds of static assets, all with useless cookies attached. The time and bandwidth consumed by unnecessary cookies soon add up.<\/p>\n\n\n\n

Removing cookies from static assets might seem straightforward, but cookies are controlled at the domain level. You can\u2019t serve assets with and without cookies from the same domain. Instead, you need a cookie-free domain just for static assets.<\/p>\n\n\n\n

There is one more domain-related wrinkle to consider when setting up a cookie-free domain. Subdomains inherit cookie settings from their top-level domain. If you set cookies for \u201cexample.com,\u201d they are also served on \u201cwww.example.com\u201d and \u201cblog.example.com,\u201d and so on. So, you can\u2019t host your dynamic content at \u201cexample.com\u201d and your static content at \u201cstatic.example.com.\u201d<\/p>\n\n\n\n

There are two ways around this:<\/p>\n\n\n\n

  1. Use a different domain to host static content.<\/li>
  2. Use a subdomain for both the dynamic content and the static content. A typical pattern is to use \u201cwww.example.com\u201d for dynamic content and \u201cstatic.example.com\u201d for static content.<\/li><\/ol>\n\n\n\n

    In our walk-through of setting up a cookie-free domain, we assume you host your site at a \u201cwww\u201d subdomain and intend to host static files at a \u201cstatic\u201d subdomain.<\/p>\n\n\n\n

    How to Create a Cookie-Free Domain for WordPress<\/strong><\/h2>\n\n\n\n

    With cPanel & WHM, creating a cookie-free domain for WordPress is straightforward.<\/p>\n\n\n\n

    1. Create a suitable subdomain.<\/li>
    2. Redirect the subdomain to serve static content from WordPress\u2019s \/wp-content directory.<\/li>
    3. Configure WordPress to serve static content from the cookie-free domain.<\/li><\/ol>\n\n\n\n

      Create a Cookie-Free Domain in cPanel<\/strong><\/h3>\n\n\n\n

      Open cPanel and navigate to the Subdomains<\/em> tool, which you\u2019ll find in the Domains<\/em> section of the main page.<\/p>\n\n\n\n

      Create a new subdomain of the top-level domain connected to your WordPress site. If your WordPress site is hosted at www.example.com, create a subdomain at \u201cstatic.example.com\u201d or similar.<\/p>\n\n\n\n

      In the Document Root<\/em> field, enter your WordPress site\u2019s \u201cwp-content\u201d directory. In this case, the site is hosted in \u201cpublic_html\u201d so we enter \u201cpublic_html\/wp-content.\u201d<\/p>\n\n\n\n

      \"\"<\/figure>\n\n\n\n

      Configure WordPress to Use the Cookie-Free Domain<\/strong><\/h3>\n\n\n\n

      We must now tell WordPress to serve static content from the new cookie-free domain. To do this, we\u2019ll add two new directives to the site\u2019s \u201cwp-config.php\u201d file. You can access the file on the command line, but you can also edit WordPress configuration files in cPanel\u2019s File Manager<\/em>, which you can open from the Files<\/em> section of the main page menu or directly in WP Toolkit<\/em>.<\/p>\n\n\n\n

      Select \u201cwp-config.php\u201d and click edit in the toolbar.<\/p>\n\n\n\n

      \"\"<\/figure>\n\n\n\n

      Add the following lines to the file, with appropriate edits to insert your subdomains<\/p>\n\n\n\n

      define(\"WP_CONTENT_URL\", \"static.example.com\");\ndefine(\"COOKIE_DOMAIN\", \"www.example.com\");<\/code><\/pre>\n\n\n\n

      Click Save Changes<\/em>.<\/p>\n\n\n\n

      Finally, we edit the site\u2019s database to redirect existing posts to the new subdomain. Before you complete this step, back up the database with WP Toolkit<\/em> or the manual method we explained here<\/a>. You are about to edit the database irreversibly. If you get it wrong, your site will no longer function correctly.<\/p>\n\n\n\n

      1. Open PhpMySQL<\/em> from the Database<\/em> section in the cPanel menu or<\/strong> access the database directly from your site\u2019s Database<\/em> tab in WP Toolkit<\/em>.<\/li>
      2. Select your WordPress site\u2019s database and then its _posts<\/em> table.<\/li>
      3. Click the SQL<\/em> tab.<\/li><\/ol>\n\n\n\n

        Enter the following SQL code in the text box. Be sure to edit the URLs to match your subdomains:<\/p>\n\n\n\n

        UPDATE wp_posts SET post_content = REPLACE(post_content,'www.example.com\/wp-content\/','static.example.com\/')<\/code><\/pre>\n\n\n\n

        Once you have double-checked the SQL, click Go<\/em> at the bottom of the page.<\/p>\n\n\n\n

        \"\"<\/figure>\n\n\n\n

        That\u2019s it! Static content will now be served from your new cookie-free subdomain, and cookies will continue being served from the \u201cwww\u201d subdomain domain.<\/p>\n\n\n\n

        As always, if you have any feedback or comments, please let us know. We are here to help in the best ways we can. You\u2019ll find us on\u00a0Discord<\/a>, the\u00a0cPanel forums<\/a>, and\u00a0Reddit<\/a>. Be sure to also follow us on\u00a0Facebook<\/a>,\u00a0Instagram<\/a>, and\u00a0Twitter<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"

        Cookies are how websites remember. Without them, they forget you as soon as a page finishes loading. This ability to remember allows you to log in to a content management system or put products in an ecommerce shopping cart. It\u2019s what allows a dynamic CMS like WordPress to personalize web pages. But sites don\u2019t need […]<\/p>\n","protected":false},"author":77,"featured_media":65833,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[289],"tags":[],"class_list":["post-61837","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general-knowledge"],"acf":[],"yoast_head":"\nHow To Use Cookie-Free Domains for Faster Website Performance | cPanel<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Use Cookie-Free Domains for Faster Website Performance | cPanel\" \/>\n<meta property=\"og:description\" content=\"Cookies are how websites remember. Without them, they forget you as soon as a page finishes loading. This ability to remember allows you to log in to a content management system or put products in an ecommerce shopping cart. It\u2019s what allows a dynamic CMS like WordPress to personalize web pages. But sites don\u2019t need […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/\" \/>\n<meta property=\"og:site_name\" content=\"cPanel\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cpanel\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-25T17:31:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/devel.www.cpanel.net\/wp-content\/uploads\/2021\/08\/Cookie-Free-Domains.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"475\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"cPanel Community\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cPanel\" \/>\n<meta name=\"twitter:site\" content=\"@cPanel\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cPanel Community\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/\",\"url\":\"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/\",\"name\":\"How To Use Cookie-Free Domains for Faster Website Performance | cPanel\",\"isPartOf\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/#website\"},\"datePublished\":\"2021-08-25T17:31:19+00:00\",\"dateModified\":\"2021-08-25T17:31:19+00:00\",\"author\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8\"},\"breadcrumb\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/devel.www.cpanel.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Use Cookie-Free Domains for Faster Website Performance\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/devel.www.cpanel.net\/#website\",\"url\":\"https:\/\/devel.www.cpanel.net\/\",\"name\":\"cPanel\",\"description\":\"Hosting Platform of Choices\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/devel.www.cpanel.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8\",\"name\":\"cPanel Community\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g\",\"caption\":\"cPanel Community\"},\"description\":\"The web hosting industry's most reliable management solution since 1997. With our first-class support and rich feature set, it's easy to see why our customers and partners make cPanel & WHM their hosting platform of choice. For more information, visit cPanel.net.\",\"sameAs\":[\"https:\/\/cpanel.net\"],\"url\":\"https:\/\/devel.www.cpanel.net\/blog\/author\/cpadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Use Cookie-Free Domains for Faster Website Performance | cPanel","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/","og_locale":"en_US","og_type":"article","og_title":"How To Use Cookie-Free Domains for Faster Website Performance | cPanel","og_description":"Cookies are how websites remember. Without them, they forget you as soon as a page finishes loading. This ability to remember allows you to log in to a content management system or put products in an ecommerce shopping cart. It\u2019s what allows a dynamic CMS like WordPress to personalize web pages. But sites don\u2019t need […]","og_url":"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/","og_site_name":"cPanel","article_publisher":"https:\/\/www.facebook.com\/cpanel\/","article_published_time":"2021-08-25T17:31:19+00:00","og_image":[{"width":1200,"height":475,"url":"https:\/\/devel.www.cpanel.net\/wp-content\/uploads\/2021\/08\/Cookie-Free-Domains.png","type":"image\/png"}],"author":"cPanel Community","twitter_card":"summary_large_image","twitter_creator":"@cPanel","twitter_site":"@cPanel","twitter_misc":{"Written by":"cPanel Community","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/","url":"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/","name":"How To Use Cookie-Free Domains for Faster Website Performance | cPanel","isPartOf":{"@id":"https:\/\/devel.www.cpanel.net\/#website"},"datePublished":"2021-08-25T17:31:19+00:00","dateModified":"2021-08-25T17:31:19+00:00","author":{"@id":"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8"},"breadcrumb":{"@id":"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/devel.www.cpanel.net\/blog\/general-knowledge\/how-to-use-cookie-free-domains-for-faster-website-performance\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/devel.www.cpanel.net\/"},{"@type":"ListItem","position":2,"name":"How To Use Cookie-Free Domains for Faster Website Performance"}]},{"@type":"WebSite","@id":"https:\/\/devel.www.cpanel.net\/#website","url":"https:\/\/devel.www.cpanel.net\/","name":"cPanel","description":"Hosting Platform of Choices","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/devel.www.cpanel.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8","name":"cPanel Community","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g","caption":"cPanel Community"},"description":"The web hosting industry's most reliable management solution since 1997. With our first-class support and rich feature set, it's easy to see why our customers and partners make cPanel & WHM their hosting platform of choice. For more information, visit cPanel.net.","sameAs":["https:\/\/cpanel.net"],"url":"https:\/\/devel.www.cpanel.net\/blog\/author\/cpadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/posts\/61837"}],"collection":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/comments?post=61837"}],"version-history":[{"count":0,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/posts\/61837\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/media\/65833"}],"wp:attachment":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/media?parent=61837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/categories?post=61837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/tags?post=61837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}