Creating a cookie-free domain to serve static content
I am trying to create a "example.com" domain to serve static content to my original domain. How would I make the "example.com" domain to so its cookie-free when loading content? I am thinking that this should be done using a htaccess file but not too sure and the information online is hard to follow. I would also like to enable gzip on the static domain to reduce the download size of static content. How would I set this up?
I would like to set this up on my Apache server to load images. Any specific ideas or instructions would be appreciated!
Thank you Pawel
Don't bother setting up gzip compression for images unless you are serving uncompressed image types.
All the common image types (png, gif, jpeg) are already compressed and you will not gain much at all (if anything) from recompressing with gzip. It will just take up more resources for users when their browser receives them.
Gzip on the web should only be used for text content like javascript, css and html.
As for cookies, I agree with Devin. Just don't set cookies on that domain and it will be a cookie free domain.
Edit to expand on my answer:
If the static content you speak of is html, js, and css, it would be better to create a handler in a server-side language to see if people have gzip enabled in their browser. Almost everyone should have it enabled, but some don't and you'd be cutting them out. You would have to keep a standard version of each file and then another version of it gzipped ".gz".
You could just enable mod_deflate on apache to compress certain types of files, but it would do on-the-fly compression every time the file is requested. That is a waste of CPU in my opinion, which is why I suggest you keep two copies of the static files like I suggested and use a server side language to determine which to send.
If you have www.example.com
, store.example.com
and images.example.com
, you will not be able to set a wildcard cookie *.example.com
in your www
site that will persist in the store
site (for example to transfer a shopping cart) without it also being sent to images
site by browsers.
This one reason site choose to use additional domains like example-static.com
- another reason for doing so is if you decide to use a third-party CDN rather than buying additional servers yourself, in which case it can simplify configuration. The downside is that if you serve flash content from a different domain, you may need to watch out for cross-domain restrictions.
Not sure I understand. If you don't send any cookies tied to this domain, then there won't be any cookies. Cookies are only sent for your domains if your software tells them to be sent, they aren't something users put there arbitrarily.