Websites for sale:
Used Cars for Sale - $175 and Car Sale.
If interested drop me a line at ken@kensfi.com. Thanks!
Have questions about Toronto? Check my latest project: Ask about Toronto!
Serve static content from a cookieless domain
These days I found Page Speed plugin and since I’m a site-speed freak I said to give it a try.
On my tests I used FF with page speed, firebug plugins.
Page Speed plugin has a tab that shows you what steps needs to be done to speed up your page. I won’t explain again each step of their analysis.
After few hours of research on cookieless domain step found the solution, but you must have full access to your DNS records and some Unix administration background (VPS or dedicated server).
Let’s consider maindomain.com your domain with cookies and your seconddomain.com the one without them.
1. Create A record for maindomain.com called images (images we want loaded without cookie)

2. Create CNAME record on seconddomain.com called images and point it to images.maindomain.com (domain on right box ends with . )

3. Check results with host / dig command.
images.seconddomain.com is an alias for images.maindomain.com.
images.maindomain.com has address YOUR_IP
The final step is to create a VirtualHost in your apache configuration for images.maindomain.com and give it a DocumentRoot.
ServerName images.maindomain.com
ServerAlias www.images.maindomain.com
DocumentRoot /home/maindomain/public_html/images
ServerAdmin webmaster@images.maindomain.com
UseCanonicalName On
..... (I removed some of the lines)
</virtualhost>
Even with VH done images.seconddomain.com still doesnt work. You have to add another alias to the images.maindomain.com like below:
ServerName images.maindomain.com
ServerAlias www.images.maindomain.com images.seconddomain.com
DocumentRoot /home/maindomain/public_html/images
ServerAdmin webmaster@images.maindomain.com
UseCanonicalName On
..... (I removed some of the lines)
</virtualhost>
Don’t forget to restart Apache (service httpd restart or from WHM – services)
And you are done!
To check if you have or not cookie on both test subdomains do the following part.
1. Open firebug(NET Tab – click on link there to see header content) or any other plugin which can read headers.
2. Open / reload an image from main domain: images.maindomain.com/image1.jpg – you should see a cookie content
3. Now open / reload same image from other domain: images.seconddomain.com/images1.jpg – no cookie.
Any comments/notes are appreciated ;)
Testking offers you superb online training for all kind of Microsoft carts like mcp, the most desired mcpd and mcts.
If you enjoyed this post, make sure you subscribe to my RSS feed!Related Posts
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.
Please read before commenting:
I don't tolerate spam comments. Be human and polite. If you are signing as "Computer repairing", "iPhone store" or other kind of bullshits you'll be marked as spam.
USE YOUR NAME! Thanks!


From what I understand is that the cookie is send in every request to the server which costs bandwidth and speed. But is it send to every image or just on every browser refresh?
Cookie goes on every piece of data you get from server (image/html, everything).
I’m trying to reduce the bandwith of a website which has about 60k visitors a day with 25 traffic. My cookie is just 430bytes but this ads up with a lot of requests of every image used in my website. Thank you for your answer ;)
Yes, I did that on one of my sites because my cookie was around 1k * 100K images – you do the math.
I read somewhere that google analytics script is setting a wide-site cookie (subdomains included). If you do need GA you have to use a cookiless domain, and if not use setcookie() with fixed domain.
Well, that’s the odd part. I did used setcookie with fixed domain to http://www.url.com but didn’t seem to matter. Suppose it’s the GA settings this 430 bytes cookies..
Hi, thanks for your post.
In the two last comments you say to use setcookie(), how can I do it?
Regards!
@Eric, yes, GA sets wide-site cookie.
@Marc, use domain value on setcookie function like:
setcookie(“testVar”, “someValue”, time() + 3600, ‘/’, ‘www.domain.com’)
or
setcookie(“testVar”, “someValue”, time() + 3600, ‘/’, ‘subdomain.domain.com’)
You can set cookie on domain www and leave nocookie on others(images, css…whatever you use for your media content).
Hope this helps
Thanks,
So, if I don’t want to use cookies in the subdomains I only have to write the following into the www site:
setcookie(“testVar”, “someValue”, time() + 3600, ‘/’, ’subdomain.domain.com’)
Am I right? Or should I also do something in the subdomains?
Thanks and regards!
www it’s a subdomain (common for a site) . In your case set the cookie for http://www.domain.com and load pictures from images.domain.com.
Have you tried using YSlow? It’s a good plugin to speed up your webpages also.
Hi
Is possible to setup cookie less domain with out a new domain ? this will cause extra cost for us