Mmm Cookies. jQuery-cookie.js

Last year I was working on a project that required the use of cookies after a few Google searches determined that the best jQuery cookie plugin from was from Carhartl.  However there was one issue, I needed to create a cookies that would expire in a matter of minutes or seconds not days.  So since his project was hosted on Github I decided that I should fork it and make some modifications.

What I did was add another parameter called expirationUnit.  This would take a string telling the plugin how to calculate the already existing parameter called expires.

Here is an excerpt from the documentation that is hosted on my Github page

Create expiring cookie, 5 minutes from then:

$.cookie('the_cookie', 'the_value', { expires: 5, expirationUnit:'minutes' });

Create expiring cookie, 30 seconds from then:

$.cookie('the_cookie', 'the_value', { expires: 30, expirationUnit:'seconds' });

I never create a pull request for this because I figured that this was a very specific use case.  But if you need this functionality you can find it on my Github account.

Leave a Reply