randomguy
randomguy

Reputation: 12252

Is there a way to prevent browser from sending a specific cookie?

I'm storing some preference data in cookies. However, I just noticed that this data gets sent to the server with every request. Is there a way to prevent that from happening?

A friend tipped off web storage, but this still leaves IE6/7 without a solution.

Upvotes: 4

Views: 3464

Answers (3)

Dan Grossman
Dan Grossman

Reputation: 52372

The appropriate solution is to not store a huge amount of data in a cookie in the first place. Store it on your server, and only store a reference to the information (like a row identifier from a database) in the cookie.

Upvotes: 3

Summer
Summer

Reputation: 2498

Nope, no way to change it. Cookie data gets sent back with every single request to the same server, including requests for static stuff like images, stylesheets and javascript.

If you want to speed up the site and minimize server bandwidth, use a different domain name - or better yet, a CDN like Rackspace Cloudfiles - for your static stuff. The cookies won't get sent to the different domain.

Good luck!

Upvotes: 1

Quentin
Quentin

Reputation: 943634

You can set cookies to be HTTP Only (so supporting browsers won't let JS access them), but not the other way around.

Web storage is the ideal solution, but you'll need to fallback to cookies for legacy browsers.

You can reduce the number of requests that include the cookies by moving some content (images, css and stylesheets in particular) to a different hostname, and limit the cookies to your primary host name.

Upvotes: 3

Related Questions