Subcookies V2

My Subcookies article from May the 27th of last year has proven to be my most popular bit of writing.

A year after publishing, "C" has requested an update.

I have now rewritten my cookies script, fixing some issues pointed out by "C", and added some security as pointed out by Jim Thomson.


Notable changes:

Note; for a complete rundown of the original script, read Subcookies.

  // bake a new cookie
  subcookiejar.bake ('admin', {
    name: 'Harmen',
    age: 23,
    homepage: 'http://www.whatstyle.net'
  }, 2);
  
  // fetch it
  var admin = subcookiejar.fetch ('admin');

…you can fetch the admin’s values by doing something like this:

  alert (admin.name);
  alert (admin.age);
  alert (admin.homepage);

…the result will be a combined object containing both the new data and the existing data: { name: 'Harmen', age: 23, homepage: 'http://www.whatstyle.net', city: 'Harderwijk', country: 'The Netherlands' }

Note that you will overwrite the existing values if you use this technique.

Other changes consist purely of improving some code, comments and security checks.

So, the new version can be downloaded here. Go and grab it, it’s free!

As always, I’d love to hear feedback. If you have any, do let me know.
And C, sorry to keep you waiting ;).