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”.