Serve static content from a cookieless domain – Google Page Speed Tip

Ok, so you are using the Google Page Speed plugin for Firefox and you can’t figure out how to clear the “Serve the following static resources from a domain that doesn’t set cookies” issue so that you score better…

First off, since we are using the Windows platform for our hosting, this entire post is making a big assumption you are too. If you are using some other platform or don’t have complete console or remote desktop access to your server, you can read on, but you’ll need to figure out this on your own.

The main thing you need to do is to REGISTER A NEW DOMAIN – or use one you’ve never used before – to specifically use for image and non-html things like JS and CSS.

If the web site is at this-is-my-site.com you should register this-is-my-site-static.com or something similar. YOU MUST register or use a completely different domain name than the base site.

Why is this? Because the way browsers store and cache cookies locally, even if you create a subdomain of your existing site, like static.this-is-my-site.com, the Google Page Speed score will still detect that that domain accepts cookies, and this will not suffice. Pick a domain that you’ve never used or hosted before and this will work fine. Keep in mind your web site visitors are NEVER going to know your images on are a different domain unless they start poking around in your HTML source code anyways.

This specific information will reference IIS 7.0, so if you are on an earlier version feel free to comment and I will see if I can pass along the settings.

So now that you’ve got your new and unused domain name ready to do, setup a new web site instance on your web server, preferably the latest OS such as Windows 2008 server.

DO NOT START the site after you set it up. Bind the site IP to the new domain name.

Bind it to the NO-MANAGED-CODE Application pool.

On this specific site you created, double click HANDLER MAPPINGS. Remove ASP, ASP.NET, PHP or any other script based handlers that appear here. ISAPI ones are OK to keep.

Start the web site instance.

You’ll now need to copy over your images to the new domain (via FTP or however).

Copy the following types of files

  • All images – png, gif, jpg
  • CSS files
  • favicon.ico file
  • JS files

In your HTML on your base site you’ll need to update ALL the image, CSS, JS, Favicon, and JS references to point to the server. You should know how to do this if you can get this far. We are talking HTML 101 here… 🙂

If you’ve done this all properly, re-run the Google Page Speed plugin and it should remove these issues off your task list and change them to “green checks”. If it doesn’t you probably have some script engine enabled on the domain and it is setting a cookie automatically (like ASP.NET). Remove it off that site.

Here at Amixa we use a dedicated server with all the script engines (ASP, ASP.NET, etc.) completely disabled to “serve cookieless domain content”.

8 comments

  • Windows User

    Thanks for this post! I’ve already wasted an hour trying to solve this “problem”, but I won’t have to waste any more time now!!

  • If you set your cookie domain to http://www.domain.com instead of .domain.com (the default), every other subdomain becomes cookieless.

  • RE: Set Cookie Domain. That may be a solution to help SOME users, however, the usage of that really depends on the programming language being used, code techniques, etc. There may be a few to hundreds of places that a web site may need to be updated to make that practical. I am not discounting the possiblity that your suggestion will work, it just may not be practical for some users to do it that way, rather than setting up another domain name and going the route I detail above. Also if you go about trying to adjust the site to a different cookie domain, eg. from microsoft.com to http://www.microsoft.com that may have consequences – such as losing all the users’ cookies that have been set over time for auto-logins, etc. Changing the cookie domain mid-stream on a site may break functionality that depended on a certain cookie value that was previously set. So… by going the route of setting up a new domain and not adjusting the COOKIE DOMAIN is the more conservative approach to improving your Google Page Speed score.

  • Thank you so much!!! But if I will use static IP address, will it run???

  • It doesn’t matter if you are using a static IP or not. You MUST use a different domain name than the base site. They can be on the same IP address, but they have to be different domain names, and the domain for the cookieless site has to be configured as I detail above, so that the site doesn’t set cookies.

  • as you suggest register another domain. But it works ?
    this solution works with sub domain ?

  • Hello Aplesh.

    Presuming that your current domain is abc123.com and that it has cookies, etc. you would need to use a completely different domain like abc123a.com and then remove all handlers and adjust the application pool settings as mentioned above. If you do all that properly, the abc123a.com will pass no cookies or session cookies and be a cookieless domain. It will NOT work just to do a subdomain of the existing one like alt.abc123.com since the parent domain abc123.com has cookies.
    Thank you!

  • Pingback: visit this link

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.