[whatwg] HTML Cookie API

Adam Barth w3c at adambarth.com
Wed Feb 24 13:07:02 PST 2010


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.

Adam



More information about the whatwg mailing list