Cookies provide an essential service to web developers, giving us a quick way of deciding whether someone has visited our site before and allowing us to tailor the site to them in some simple way if they have, by providing a welcome message, or by putting any moveable elements into a particular configuration for example. The only problem with cookies is not that they are particularly hard to work with, it's just that they're so cumbersome to code for, as anyone that's used them will know.
Thankfully, the YUI provides us with an easy way of setting and getting cookie data, which abstracts away the strict syntax and dramatically shortens our scripts which is a very good thing considering even the most basic functions for getting and setting cookie data are often in excess of 20 lines of plain-vanilla JavaScript, even without error checking that prevents an error being thrown if document.cookie is empty.
Throughout this tutorial I'm going to be assuming that you've worked with cookies before the old fashioned way and understand the principles behind their use. Even if you've never worked directly with cookies before however you should still be able to use the YUI Cookie utility without any difficulties. The examples in this tutorial have been tested on a variety of the most common web browsers in use today, but only on the Windows platform. You should note that these examples do not work seem to work in Google Chrome.
Read More