Over the past week, I have had the opportunity to explore the YUI Cookie object. It has all the functionality from the 2007 article on Cookies, with the addition of sub cookies. Sub-cookies get around the maximum number of available cookie limitation, by allow the developer to store multiple cookies inside of one cookie. This is especially useful for sub-domains, see YUI -Cookie for more information.

However, there are a few methods that were missing: getNumberOfCookies, getCookieSize, and isCookiesEnabled. The getNumberOfCookies function returns the number of cookies currently set; simply splitting around ; seems to work in the browsers I tested. Let me know if there is a better way or browser issues I missed. The getCookieSize method does a pretty good estimation of the cookie size, by assuming all alpha-numeric characters are not escaped and thereby stored as 1 byte and all non-alpha-numeric characters are escaped and thereby stored as 3 bytes. Although, the later is not always true, it is a fairly accurate assumption; I am open to a better regex that considers the other characters which are not escaped. Lastly, the isCookiesEnabled enabled function determines if Cookies are enabled, first by looking at the navigator object, then by checking if there is a cookie set, and lastly by adding a test cookie.

With these methods included in addition to YUI, you can determine if you should use cookies to store user information (using isCookiesEnabled) and parse large data between multiple cookies (using getNumberOfCookies and getCookieSize). The worst case scenario will be that each cookie can not be larger than 4000 bytes and that you can not have more than 20 cookies per domain.