Archive for February, 2009

YUI Cookie utility and single-page cookies

Monday, February 9th, 2009

I’m doing a bit of work with cookies, so I figured that I’d give YUI’s Cookie utility a try. Got it up and running on a proof of concept with no problem and it worked pretty well. However, once I moved off the proof of concept, it seemed like my cookies were only living for one page.

A quick inspection with Firecookie revealed that the Cookie utility was creating a huge number of cookies with the same name and binding them to a single page by default. (At least in 2.5.2). If you’re on that branch (I can’t upgrade a production instance, for example), make sure you add a path to the cookie you’re creating if you’d like the cookie to be readable and writable by more than the page you’re on. That would look something like this:

        YAHOO.util.Cookie.set('someName','someValue, {
            expires : new Date('January 1, 2010'),
            path : "/"
        });

That will make your cookie readable beyond a single page and might save you a headache.

I'm Reading…
Search This Site
You are currently browsing the A Modern Fable weblog archives for February, 2009.

AddThis Feed Button

Need great hosting?

Categories