Cookies wtf!!

Just wanna bark that out: Who the hell did the design for document.cookie ?

I was a naive guy coming from my known little world of C++ server backend programming to this godless land of web development and my head blew off 😀

Thats how I felt a lot of times making my steps in this unknown and hostile environment. But I never felt as disenchanted as I felt when I start to use cookies in my js code. All the rest was more or less ‘consistent’ in its twisted kind of way and I thought I was starting to get my head around things. But man was I confused when I started to wrap my cookie code together “just to remember the login”. “It can’t be so hard” I thought – I was wrong!

  1. Why on earth is document.cookie like a property where nothing else works like this?
  2. You can get all cookies in one gigantic key=value separated string … Seriously ? Ok I get split that myself…
  3. document.cookie = “” and document.cookie = null does nothing that you would expect (It actually does nothing at all)
  4. document.cookie = “foo=bar” ADDs this single cookie (Like it magically became a function call…)
  5. And finally my favorite: To loose a cookie entry you actually have to update it with a expiration date that is in the past !!!! Seriously ? WTF !!!

That’s when I started looking for a lib to keep my sanity!
Believe me you don’t want to keep up with this crap, go grab jquery-cookie:

Leave a Reply