javascript - Is there a way to prevent browser from sending a specific cookie? - Stack Overflow

I'm storing some preference data in cookies. However, I just noticed that this data gets sent to t

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.

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.

Share Improve this question asked Feb 11, 2011 at 14:39 randomguyrandomguy 12.3k16 gold badges76 silver badges102 bronze badges 2
  • Why can't you ignore the cookie server-side? – RoToRa Commented Feb 11, 2011 at 14:42
  • Oh, I do that, but this creates unnecessary HTTP traffic as the cookie is sent with every request. The cookie makes a normal GET request 5-10 times bigger than it would be without it. – randomguy Commented Feb 11, 2011 at 14:48
Add a ment  | 

3 Answers 3

Reset to default 3

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.

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.

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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744285143a4566761.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信