[whatwg] HTML Cookie API

Nicholas Zakas nzakas at yahoo-inc.com
Wed Feb 24 17:00:57 PST 2010

Even though there can be multiple cookies with the same name on a single document, this most frequently occurs due to error rather than intention. I've never received a YUI bug report about this occurrence though I have considered returning an array of values instead of just the first value in this case. I might just go do that now. :)

My initial comment still remains: retrieving the value of a single named cookie seems to be a much more common use case than retrieving all cookies. You can choose to solve the duplicate cookie name issue in a number of ways, but not providing a way to access a cookie by name seems like a flaw in this design.

Of course, if the main use case you're concerned about is retrieving all cookies, then feel free to disregard this feedback.

Commander Lock: "Damnit Morpheus, not everyone believes what you believe!"
Morpheus: "My beliefs do not require them to."

-----Original Message-----
From: Adam Barth [mailto:w3c at adambarth.com] 
Sent: Wednesday, February 24, 2010 1:07 PM
To: Nicholas Zakas
Cc: Darin Fisher; whatwg
Subject: Re: [whatwg] HTML Cookie API

On Wed, Feb 24, 2010 at 11:11 AM, Nicholas Zakas <nzakas at yahoo-inc.com> wrote:
> I like the idea of creating an easier way to deal with cookies (which is why I wrote the YUI Cookie utility way back when). The thing that seems to be missing in your proposed API is what I consider to be the most common use case: retrieving the value of a single cookie. There's not many times when I need to get every single cookie that's available on the page, but there are plenty of times when I want to check the value of a single cookie. Using your API, getting the value of a single cookie with a known name becomes:
>    document.getCookies(function(cookies) {
>      for (var i=0; i < cookies.length; ++i){
>          if(cookies[i].name == "my_cookie_name"){
>              doSomething(cookies[i]);
>          }
>      }
>    });
> That seems like a lot of work just to retrieve a single cookie value.

The problem is there can be multiple cookies with the same name for a
given document.  The YUI Cookie utility seems to assume there's only
one.  We could add a facility for filtering the results of getCookies,
but that's easy enough to do correctly in JavaScript.


More information about the whatwg mailing list