views:

59

answers:

2

When analyzing my various websites pages with Google Page Speed, I always have the following recommendations:

  • leverage browser caching
  • serve static content from a cookie-less domain

I have no idea on how to eliminate or implement these messages. Can this be done:

  • through .htaccess
  • through php code
  • Apache configuration

How can this be done?

A: 

For "serve static content from a cookie-less domain" you can create a subdomain in which you add a .htaccess file containing:

Header unset Cookie
Header unset Set-Cookie
gulbrandr
Besides that [`Header`](http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header) is only for response header fields but *Cookie* is a request header field, removing such header fields doesn’t change the fact that the cookies *are* sent by the browser in the first place.
Gumbo
This is wrong, as Gumbo said. For cookie-less requests, use a whole new domain, i.e. "mysite-static.net".
Coronatus
@Coronatus: You can use a subdomain and make it cookie-less.
Gumbo
@Gumbo - That's much more effort, forces you to use `www.`, and means you can't access `www.`'s cookies on another sub-domain, e.g. `secure.`
Coronatus
@Coronatus: "For cookie-less requests, use a whole new domain". So it is not possible to create cookie-less subdomains?
gulbrandr
@gulbrandr - it is, but then you get the problems mentioned above. Quicker (and cheaper because of the time saved) to use a new domain.
Coronatus
+1  A: 

The Page Speed project page has a pretty detailed information about the recommendations including Leverage browser caching and Serve static content from a cookieless domain. Read these first and try to understand the problems and proposed solutions.

After that you can implement these recommendations. As you’re using an Apache web server, read Apache’s Caching Guide and the documentation to mod_expires, Apache’s main module for time based HTTP caching. And as for the cookie-less domain, read Apache’s virtual host documentation. With that you can set up a virtual host for your cookieless domain. Then you just need to make sure that your cookies are not valid for that domain (see Domain parameter).

Gumbo