Loading static content from a cookieless subdomain

  Previous article Next article  

Minimize your HTTP requests generating your CMS Made Simple-powered website by loading static content from a cookieless subdomain.

I investigated and have setup this method using my own websites and at my web host using cPanel. It is of course also possible at other platforms but I did not test and describe it here...

In my tutorials I use "" as the default domain name in text and code.
It seems obvious, but it does bear repeating! Change this to *your* domain name!

  How to use

 1. Create subdomain

In cPanel, open in the "Domains" section the "Subdomains" button.

Here you create a new subdomain "static" of your main domain.

Important! Point this subdomain to the folder where your main website is stored!
At most websites this will be: public_html.
But if your website is stored in a subfolder you need to add something like public_html/subfolder depending your settings.

After clicking the "Create" button the subdomain will be installed at your server.
This subdomain is an alias of the main domain without changing DNS (a/cname) settings.

 2. Enable SSL with Let's Encrypt (optional)

In the "Security" section of the main cPanel page, you open the "Let's Encrypt™ SSL" page.

Issue a new certificate for the subdomain "" you just created.

 3. Change CMSMS config file

Add to the bottom of your config.php file (don't forget the change the file permission to not-writable afterwards)

// Point all uploads paths to the static domain
$config['uploads_url'] = '';

// Change path for templates and stylesheets
$config['public_cache_url'] = '';

// I needed to set this line, it might be you don't need it...
$config['ssl_css_url'] = '';

 4. Update analytics code

Whether you use Matomo (before Piwik) or Google Analytics you need to update the code to prevent setting cookies for all subdomains. By default the cookie will be installed for "" (note the dot!) or "*". It has to be changed, so it only sets cookies for the current domain "".

4.1 Example Matomo (Piwik)
_paq.push(["setCookieDomain", "*"]);
_paq.push(["setDomains", ["*"]]);

Remove "*." twice.

_paq.push(["setCookieDomain", ""]);
_paq.push(["setDomains", [""]]);
4.2 Example Google Analytics
_gaq.push(['_setDomainName', '']);

Remove "." once.

_gaq.push(['_setDomainName', '']);

 5. Update paths in the (core) templates and stylesheets

The theme and content files of your website are (mostly) stored in the uploads and/or assets folders. In example Change the paths to No need to move the files!

 6. Update path in CGSmartImage

Do you use the CGSmartImage module at your site? Simply change the paths by changing these settings in the "General" tab.

1. Image Url Prefix:

2. Does the URL above acount for the cache path? Yes

7. Done!

These are all the steps you need to do!
When I use PingDom speedtest I can see at my website 73% of the HTTP requests are now done from the cookieless domain!
The website has certainly become faster by doing this!!!

  Working example

Buy Me A Coffee

  Comment Form


Click here to open the form



No comments yet...

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

Loading static content from a cookieless subdomain

  Article optimized for CMSMS 2.x

  Last tested in: CMSMS 2.2.19
  Last updated: 30-11-2020
  Comments: 0

Buy Me A Coffee


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!