3 Rules for Efficient Cookie Management

As I pointed out previously, one of the leading sources of wasted bandwidth is improper use of cookies. With that in mind, here are the most important rules for proper cookie management:

  1. Keep them small – don’t use cookies to maintain view state or other large data blobs. Technology has advanced to the point where we should be past those dark ages of using browsers to do the dirty work. Use a common memory cache, a DB or even a file.
  2. Keep them targeted – you can specify the URLs that should receive a given cookie. By default, no URL or path is specified and this means that the cookie is transported on every request, even requests for images, script files and other non-business content. That can add up to an enormous waste of time transporting cookie data that no-one needs.
  3. Prefer session-tracking – all web servers have the ability to track sessions, if you turn on that feature. Even a stateless application can do it. The only difference between tracking sessions and tracking users is the duration of the ID cookie in the user’s browser. A new session ID is handed out on every session the user has with the application (typically by the web server). A user ID is only given out once, typically by the application. If you want to remember preferences for an anonymous user, it doesn’t mean that he has to sign in or register. It just means that you need to set a user ID cookie with a random number or string and associate the user’s preferences with that ID in some centralized location. Using just a session ID and user ID, you can keep all of your bulky information inside your application and off the network.

NOTE: you should never put any targeting on session IDs or user IDs, since that will interfere with effective monitoring of your application.

Don’t introduce needless bottlenecks and overhead through bad cookie practices. Keep them small and targeted at all times. Most importantly, always question whether you truly need them or are just being lazy.

These postings are my own and do not necessarily represent BMC's position, strategies, or opinion.

Share This Post