Serve static content from a cookieless domain ...

13 views
Skip to first unread message

UVL

unread,
Oct 19, 2009, 5:19:41 AM10/19/09
to page-speed-discuss
Hello, have failed to follow the advices about using the cookieless
domain.

Let's suppore my site is "www.mysite.com", I've moved all the static
images to "s.mysite.com", and I use it only for that.

Using Firebug, I see that those images still have cookies, and the
content is the following:

__utma=105240007.1061351544.1255943854.1255943854.1255943854.1;
__utmb=105240007.1.10.1255943854; __utmc=105240007;
__utmz=105240007.1255943855.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=
(none)

looks like the one created by google analytics! (I use GA, but only in
the "www" domain pages)

The advices from Google are the following:
"To reserve a cookieless domain for serving static content, register a
new domain name and configure your DNS database with a CNAME record
that points the new domain to your existing domain A record. Configure
your web server to serve static resources from the new domain, and do
not allow any cookies to be set anywhere on this domain. In your web
pages, reference the domain name in the URLs for the static
resources."

"and do not allow any cookies to be set anywhere on this domain" ...
How this can be done? Is there some apache configuration to prevent
this? But being the cookies from other sites, is there something that
I can do?

Thanks for your help.

Kara Moscoe

unread,
Oct 19, 2009, 12:39:31 PM10/19/09
to page-spee...@googlegroups.com
In the case you are citing, you are still using the same domain, mysite.com. When a cookie is set for a domain, it is set for all hosts on that domain. (Even though you only use the GA code on the www page, the GA code probably sets the cookie on the general domain name, not on a specific hostname.)  You need to have an entirely different domain name, e.g. myothersite.com.

Does that help?
Kara

musicisair

unread,
Oct 20, 2009, 9:50:13 AM10/20/09
to page-speed-discuss
You can fix this in your initialization code using:
var ga =_gat._getTracker("UA-########-#");
ga._setDomainName("www.domain.com");
...

On Oct 19, 12:39 pm, Kara Moscoe <kmos...@google.com> wrote:
> In the case you are citing, you are still using the same domain, mysite.com.
> When a cookie is set for a domain, it is set for all hosts on that domain.
> (Even though you only use the GA code on the www page, the GA code probably
> sets the cookie on the general domain name, not on a specific hostname.)
> You need to have an entirely different domain name, e.g. myothersite.com.
>
> Does that help?
> Kara
>

Satyakaran

unread,
Oct 20, 2009, 10:06:11 AM10/20/09
to page-speed-discuss
It is useful for me also.

Andrea

unread,
Dec 9, 2009, 4:28:32 AM12/9/09
to page-speed-discuss
I have the same problem but I'm using the new asyncronous analytics
code.
What to do ?

EnviroChem

unread,
Dec 13, 2009, 7:17:48 PM12/13/09
to page-speed-discuss
How much does it even matter if images and are static content are
served from a domain where other dynamic content serve up cookies if
the server isn't pushing cookies with the static content? If static
content is cached for an extended period of time, would there even be
requests for cached content that hasn't expired?

My observation is that, a typical request to a domain that uses Google
Analytics would include a cookie string about 200 bytes long. The
thing is you really wouldn't save that whole 200 bytes of data
transmission and resulting latency because the HTML file would be come
larger as a result of having to include the new domain name as part of
the URL for every object called from the secondary server. In
addition, you add another DNS request. It just seems that this is a
very minimal speed increase for a lot of extra work to retool a site
to hand off say images to a second domain.

musicisair

unread,
Dec 14, 2009, 9:04:37 AM12/14/09
to page-speed-discuss
Cookies will be SENT from your browser to the web server with each
request...even if the server never plans on sending the cookies back.

If you have 20 images on a page (a gallery perhaps) at
static.mysite.com there is only need for one additional DNS lookup:
static.mysite.com; which will have no cookies sent/received. In the
case of CSS and Javascript (gzip/deflated), 200 bytes of cookies could
send you over the 1460 TCP packet byte size...which would cause the
file to accumulate another RTT; and suffer from the mysteries of
packet loss and other latencies.



On Dec 13, 7:17 pm, EnviroChem <k...@environmentalchemistry.com>
wrote:

loot

unread,
Dec 16, 2009, 5:49:03 PM12/16/09
to page-speed-discuss
>
> "and do not allow any cookies to be set anywhere on this domain" ...
> How this can be done? Is there some apache configuration to prevent
> this? But being the cookies from other sites, is there something that
> I can do?
>
Can someone please answer this part? I'm not clear on how this is
done. It seems now to rank well in Google everyone suddenly has to
become extremely technical.

I've set up a separate domain and am serving images from there but
Page Speed is still complaining so obviously I've not done something.
I don't know why Google's guide doesn't just explain in simple terms
how to set up the domain properly.

Kara Moscoe

unread,
Dec 16, 2009, 7:17:16 PM12/16/09
to page-spee...@googlegroups.com
Can you provide some more details? For example, what host/domain names are using to serve the images from? And what is your main domain? As far as I know, cookies are not served by default by Apache, unless you explicitly set them. 

Kara


--

You received this message because you are subscribed to the Google Groups "page-speed-discuss" group.
To post to this group, send email to page-spee...@googlegroups.com.
To unsubscribe from this group, send email to page-speed-disc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/page-speed-discuss?hl=en.



Richard Rabbat

unread,
Dec 16, 2009, 7:26:03 PM12/16/09
to page-spee...@googlegroups.com
Can ypu send a link that describes your issue?
Richard

> --
>
> You received this message because you are subscribed to the Google Groups
> "page-speed-discuss" group.
> To post to this group, send email to page-spee...@googlegroups.com.
> To unsubscribe from this group, send email to
> page-speed-disc...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/page-speed-discuss?hl=en.
>
>
>

--
Sent from my mobile device

Richard Rabbat | Product Manager | Google, Inc.
E: rab...@google.com | M: +1-650-714-7618 | Google Voice: +1-617-213-0819

satya-weblog.com

unread,
Dec 17, 2009, 1:36:53 AM12/17/09
to page-speed-discuss
For those who are non technical can use the wordpress like platform
wordpress.com or blogspot for free and
wordpress package for self hosted.
if you use self hosted wordpress then you can use various plugins like
wp-super cache etc making your site fast.

Mark Widner

unread,
Dec 17, 2009, 9:17:49 AM12/17/09
to page-speed-discuss
That helps me. In all the reading surrounding this issue I have
overlooked the fact that this requires a COMPLETELY different domain.
My company uses a generic cookie *.mydomain.com since we have multiple
domains and would like to track our customers across those domains.
This is counter to the cookieless images since we would know have to
support not one but TWO new servers since the images would need to be
served up on the unsecure and secure ports. Can anyone discussion the
issues (business or otherwise) with instituting this type of setup? If
I propose something like this I would need to have good references,
cost savings to the customer to offset cost savings to the developers
who have to make changes to support a new domain. Any information
would be greatly appreciated.

On Oct 19, 10:39 am, Kara Moscoe <kmos...@google.com> wrote:
> In the case you are citing, you are still using the same domain, mysite.com.
> When a cookie is set for a domain, it is set for all hosts on that domain.
> (Even though you only use the GA code on the www page, the GA code probably
> sets the cookie on the general domain name, not on a specific hostname.)
> You need to have an entirely different domain name, e.g. myothersite.com.
>
> Does that help?
> Kara
>

Kara Moscoe

unread,
Dec 17, 2009, 10:50:53 AM12/17/09
to page-spee...@googlegroups.com
Hi Mark,

You don't actually need two separate servers. You can use CNAME records in your DNS setup to point to a single server. In other words, you can still host all the images on the mydomain.com server, but create a CNAME record for myseconddomain.com that points to mydomain.com, and use the myseconddomain.com as the referencing URL for all the images. See http://code.google.com/speed/page-speed/docs/request.html#ServeFromCookielessDomain for an example of how Google does it.

Hope this helps,
Kara 

loot

unread,
Dec 17, 2009, 5:49:04 PM12/17/09
to page-speed-discuss
Everything is hosted on a dedicated linux server running apache. For
some reason my main domain is sending cookies with the images whether
I use a subdomain to serve the images or a separate domain.

> > page-speed-disc...@googlegroups.com<page-speed-discuss%2Bunsu...@googlegroups.com>

loot

unread,
Dec 17, 2009, 5:46:50 PM12/17/09
to page-speed-discuss
How exactly do you do that in WHM? I've been unable to find simple
instructions on how to do that.

On Dec 17, 3:50 pm, Kara Moscoe <kmos...@google.com> wrote:
> Hi Mark,
>
> You don't actually need two separate servers. You can use CNAME records in
> your DNS setup to point to a single server. In other words, you can still
> host all the images on the mydomain.com server, but create a CNAME record
> for myseconddomain.com that points to mydomain.com, and use the

> myseconddomain.com as the referencing URL for all the images. Seehttp://code.google.com/speed/page-speed/docs/request.html#ServeFromCo...


> for
> an example of how Google does it.
>
> Hope this helps,
> Kara
>

> > page-speed-disc...@googlegroups.com<page-speed-discuss%2Bunsu...@googlegroups.com>

Kara Moscoe

unread,
Dec 17, 2009, 8:48:30 PM12/17/09
to page-spee...@googlegroups.com
What is "WHM"? Are you the authoritative server for your domains? Or are they hosted by another DNS provider? If you actually run your own authoritative DNS server, documentation for your Linux server will have this information. Or you can refer to generic BIND documentation e.g.https://www.isc.org/software/bind/documentation/arm95. If you are using a hosting service, you will need to request this from the service.

A subdomain won't work; cookies are set for all hosts on *.yourdomain.com. You actually need to register a new domain name and set up a new zone file for the new domain. 

Hope this helps,
Kara

To unsubscribe from this group, send email to page-speed-disc...@googlegroups.com.

Bruno

unread,
Dec 18, 2009, 3:45:55 AM12/18/09
to page-speed-discuss
The setDomainName with asynchronous seems not working

I try two code and neither
_gaq.push(['setDomainName','www.exemple.com']);
nor
_gaq.push(['_setDomainName','www.exemple.com']);
hide the cookies from my static.exemple.com server...

Andrea

unread,
Dec 18, 2009, 4:10:16 AM12/18/09
to page-speed-discuss
The same for me.

Kara Moscoe

unread,
Dec 18, 2009, 10:46:01 AM12/18/09
to page-spee...@googlegroups.com
As mentioned elsewhere on this thread, using a subdomain, i.e. static.example.com won't work. Cookies are set for all hosts on *.example.com. You actually need to register a new domain name such as example2.com and serve the static content from there.

Kara

Andrea

unread,
Dec 18, 2009, 10:53:45 AM12/18/09
to page-speed-discuss
I tried with an external domain and it doesn't work.

Analytics set the cookies.

On Dec 18, 4:46 pm, Kara Moscoe <kmos...@google.com> wrote:
> As mentioned elsewhere on this thread, using a subdomain, i.e.
> static.example.com won't work. Cookies are set for all hosts on *.

> example.com <http://yourdomain.com/>. You actually need to register a new


> domain name such as example2.com and serve the static content from there.
>
> Kara
>
>
>
> On Fri, Dec 18, 2009 at 12:45 AM, Bruno <bruno.sa...@globalis-ms.com> wrote:
> > The setDomainName with asynchronous seems not working
>
> > I try two code and neither
> > _gaq.push(['setDomainName','www.exemple.com']);
> > nor
> > _gaq.push(['_setDomainName','www.exemple.com']);
> > hide the cookies from my static.exemple.com server...
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "page-speed-discuss" group.
> > To post to this group, send email to page-spee...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > page-speed-disc...@googlegroups.com<page-speed-discuss%2Bunsubs cr...@googlegroups.com>

EnviroChem

unread,
Dec 19, 2009, 11:38:41 AM12/19/09
to page-speed-discuss
To me the secondary domain name is a PITA fix for structural design
flaw in the way browsers and servers communicate with each other.
There should be a simple and short flag sent from the server to the
browser that tells the browser to not send cookies for specific file
types.

The other thing is, this wouldn't be so much of an issue if 3rd party
widget suppliers (e.g. Google's Friend Connect & Analytics) used
smaller cookies, especially when these cookies are set for the domain
name of the website and not Google's domains. Cookies shouldn't be
used to store an entire encyclopedia of information. Why on earth
does Google need 200 bytes of information stored in cookies for just
one or two of their widgets?

gibex

unread,
Dec 19, 2009, 8:34:42 AM12/19/09
to page-speed-discuss

Sam Kerner

unread,
Dec 20, 2009, 8:06:52 PM12/20/09
to page-spee...@googlegroups.com
On Sat, Dec 19, 2009 at 11:38 AM, EnviroChem
<k...@environmentalchemistry.com> wrote:
> To me the secondary domain name is a PITA fix for structural design
> flaw in the way browsers and servers communicate with each other.
> There should be a simple and short flag sent from the server to the
> browser that tells the browser to not send cookies for specific file
> types.

There are many things about http that I would change if I could,
but getting an update into the http spec and getting all browsers to
implement the change is a huge undertaking. There is an effort to
provide an alternative to http that can get better performance:
http://www.chromium.org/spdy/spdy-whitepaper

Sam

EnviroChem

unread,
Dec 20, 2009, 8:54:34 PM12/20/09
to page-speed-discuss
Sam,

Thanks for the great link. I'm glad to see someone is working on it.
Maybe in another ten years the issue of needing a cookieless domain
for static content will be eliminated.

In the mean time I think we should lobby our ad and other widget
providers (e.g. AdSense) to use smaller cookies. I say no cookie
should be over 40 bytes, which is just enough for a 32 byte GUID and
key name. Also any widget should only place a single cookie (Google
you listening?)

Gabi Doroftei

unread,
Dec 21, 2009, 1:44:18 AM12/21/09
to page-spee...@googlegroups.com
Very good paper Sam.

--

You received this message because you are subscribed to the Google Groups "page-speed-discuss" group.
To post to this group, send email to page-spee...@googlegroups.com.
To unsubscribe from this group, send email to page-speed-disc...@googlegroups.com.

in...@eswd.com

unread,
Dec 21, 2009, 11:17:11 AM12/21/09
to page-speed-discuss
You have to use "none" for the domain name now. I don't know why they
changed it.
The following should work for you (it does for me):

// This is copied from a site that will never use HTTPS so the SSL
part has been removed.
/*<![CDATA[*/
var _gaq=_gaq || [];
_gaq.push(["_setAccount", "UA-XXXXXXX-X"]);
_gaq.push(["_setDomainName", "none"]);
_gaq.push(["_trackPageview"]);
(function(g){
g.type="text/javascript";
g.async=true;
g.src="//www.google-analytics.com/ga.js";
(document.getElementsByTagName("head")[0]||
document.getElementsByTagName("body")[0]).appendChild(g);
}(document.createElement("script")));

/*]]>*/

Google recommends putting this as the last script in the head section
of your page.

loot

unread,
Dec 30, 2009, 7:07:21 AM12/30/09
to page-speed-discuss, ske...@google.com
So did you manage to get this to work? I tried it but it still
doesn't quite work. Does the images domain have to be an addon domain
using the same nameservers as the main domain? I added the
virtualhost code to my http.conf file for my server, I assume that's
what I was supposed to do. Under YOUR_IP I put the IP of my main
domain both times...again is that what you did?

Thanks.

Gabi Doroftei

unread,
Dec 30, 2009, 2:43:55 PM12/30/09
to page-spee...@googlegroups.com
Yes, that solution is working for me. I can help you after 01.01 - out of town.

No, domain isn't addon domain, just a separate domain.
Yes, I used same main IP on both VHosts.

Happy New YEAR!

To unsubscribe from this group, send email to page-speed-disc...@googlegroups.com.

Civilized Group

unread,
Jan 24, 2010, 2:41:46 AM1/24/10
to page-speed-discuss
I am having the same experience - I setup the new domain (not just a
new subdomain but a completely new domain) and I'm still getting
yelled at by PageSpeed for cookies from my expectedly cookieless
domain!

On Dec 18 2009, 10:53 am, Andrea <andreapern...@gmail.com> wrote:
> I tried with an external domain and it doesn't work.
>

> Analyticssetthe cookies.


>
> On Dec 18, 4:46 pm, Kara Moscoe <kmos...@google.com> wrote:
>
> > As mentioned elsewhere on this thread, using a subdomain, i.e.

> > static.example.com won't work. Cookies aresetfor all hosts on *.

Bruno

unread,
Jan 25, 2010, 7:41:38 AM1/25/10
to page-speed-discuss
Check if cookies are really sent on your new domain, and where did
they come from (maybe Google analytics).
Then you can act by setting the code like recommend above.

Before testing your new configuration, remember to empty your
browser's cookies, to be sure that currently set cookies will not be
reused while you're testing.


On Jan 24, 8:41 am, Civilized Group <supp...@civilizedgroup.com>
wrote:

Reply all
Reply to author
Forward
0 new messages