fgiasson / jquery-enhanced-cookie

Enhanced Version of the jQuery Cookie plugin that uses HTML5's localStorage feature and that support chunking of values in multiple cookies to save big size content.
http://fgiasson.com/blog/index.php/2012/01/05/jquery-cookie-pluging-extended-with-html5-localstorage-and-chunked-cookies
26 stars 12 forks source link

TTL for localStorage items, $.ms for parsing expirings #1

Open creage opened 12 years ago

creage commented 12 years ago

I'm not sure if the $.ms is wanted feature, but in my custom project it helps greatly, so I went to implement it in that plugin as well.

Apart of that, I've implemented a TTL (expiring) feature for localStorage items, and changed (minified) some API keys.

fgiasson commented 12 years ago

Hi!

The TTL for the localStorage is wonder, and was missing in the previous version. So, this is perfect.

However a few questions for you:

  1. If I understand .ms, this is to specify the time in millisecond right? If so, what is the advantage there, and what kind of usecases would warrant that?
  2. You changed the name of these options, is there any reason for that?
    1. maxNumberOfCookies -> maxNumber
    2. useLocalStorage -> local
    3. maxChunkSize -> maxSize

Once I am clear with these things, I will merge these modifications.

creage commented 12 years ago

.ms provides more convenient way to set the expiration of data.

By default, original $.cookie respects only days, meaning there is no way to set a cookie for one hour, except of compute that and pass as Date object.

Using $.ms users can set any timeout in more intuitive way - $.ms("1h") means one hour TTL, $.ms("7d") means one week, etc. This brings more value while setting TTL.

Additionally, I've minified options names, to save bytes, and keep code clean. Personally I don't like kindOfVeryLongVariableNamesIntendedToBeSelfExplaining. I love following KISS principle.

fgiasson commented 12 years ago

Hi Creage!

Good for $.ms, and thanks for the explanation.

About the naming of the variables, the minding is the following: better knowing what the variable (in this case the option) is about by reading it. I share the same view as Robert C. Marting here. I agree that "kindOfVeryLongVariableNamesIntendedToBeSelfExplaining" doesn't make it, but I think that having (shorter) variable names, but still self explaining, makes reading and understanding the code much easier.

Finally, to save bytes, we are better minifying the code on production servers than making the code more obscure to the developers.

If you don't mind, I would strongly suggest keeping the previous options names; particularly since they are options more than inner code variables.

Thoughts?

exside commented 11 years ago

The TTL feature for localStorage is what I'm hardly missing about this great plugin, would be nice if this could be implemented soon =)!

fgiasson commented 11 years ago

Yeah, will have to check this. The problem was one of naming conventions. I would have to merge, fix and push I guess.