Websites for sale:
Web Hosting Reviews and Rating, Used Cars for Sale and Car Sale.
If interested please send my an email at ken@kensfi.com. Thanks!

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)

p1

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

p2

3. Check results with host / dig command.

$> host images.seconddomain.com
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.

<virtualhost YOUR_IP:80>
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:

<virtualhost YOUR_IP:80>
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 ;)

Popularity: 14% [?]

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Digg Post to Facebook

Related Posts

How to, Tips and tricks

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.

ss_blog_claim=a60fe0ab4bb2f93087f423c86b8d54f3

Comments

12 Responses to “Serve static content from a cookieless domain”

Leave Comment

(required)

(required)