How to get rid of cookies (I'm on a CDN)

The pull location for my CDN is the root of my site, www.example.com. So cdn.example.com in reality mirrors the entire www.example.com, but my site, www.example.com, only links the static content from the cdn.example.com. That’s I believe how it is also set up here at www.webpagetest.org.

Questions:

  1. What can I do to have no cookies on the images, .js, and .css?

  2. Will there be any impact on the load time? At least 10, 20, or 30ms?

1 - You can either change how you set the cookies and set them to www.example.com instead of to example.com (and you may not have control over all of them) or instead of using cdn.example.com you can use www.cdnexample.com and put the static content on a completely different domain.

2 - Possibly but it’s going to be REALLY small and depend on how large your cookies are. If you only have a few cookies and they are relatively short it’s probably not worth the effort (webpagetest.org cookies get applied to my static content as well because it’s not really worth the effort for how few there are).

Pat, you are a gentleman, and I thank you very much! I set the cookie domain to www.example.com as you suggested was one option I had. It worked, as you can see on the screenshot above.

If you do that just make sure you have a redirect for non-www to www for your site, otherwise the cookies won’t get sent if they try and access a page through non-www.

Very good point, Jarrod, thanks. I do have the redirect in my .htaccess file.

Hi guys,

I’m confused by this. There’s only one page on my site that sets cookies, and after reading this post I changed the domain from .datesphere.com to .www.datesphere.com. However, I’m still failing all the cookie tests when you look at my results.

I looked around and found the below excerpt from Yahoo’s Best Practices for Speeding Up Your Site page:

So am I just screwed forever since I already set cookies on the naked domain? This “you can’t fix it” explanation seems flat out bizarre, as I’m used to being able to fix / undo things on the internet, especially since it sounds like Marvin was able to change the cookie domain and it worked.

Any ideas on what I did wrong / why this didn’t work for me?

Thanks,

Chris

Well, you did half of the solution by setting the cookie to the fqdn, but all of the static resources are still being served from www.datesphere.com. You need to serve them from a different fqdn otherwise they will still carry the cookies (static.datesphere.com for example).

That said, cookies is probably one of the last things you should focus on. Once you reduce the number of requests you’ll be serving less than 10 requests total and it looks like there’s only the one cookie so it’s really not going to make a measurable difference.

-Pat

Oh… I get it. And when you say “you’ll be serving less than 10 requests” I guess you mean once all my images are served from a sprite (since those are the vast majority of my requests now)?

I’ll have to look into how to do this since the images are being served dynamically - have never used sprites before.

Thanks, Pat.

Yep - dynamically may be more difficult though (is it dynamically selected from a reasonable set of possible images or a huge pool of images)? Are they all dynamic or are some of them static (like the flags)?

All the images are generated based on php variables, so I guess I’d say they’re all dynamic. I understand sprites in theory (having one big image containing all your images and showing only a specific part using css rules for each individual image), but I’ll have to read up on how you make it work when images are being pulled in dynamically. I’m sure there’s a way to do it.