jquery-enhanced-cookie icon indicating copy to clipboard operation
jquery-enhanced-cookie copied to clipboard

TTL for localStorage items, $.ms for parsing expirings

Open creage opened this issue 13 years ago • 5 comments

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.

creage avatar Apr 04 '12 18:04 creage

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.

fgiasson avatar Apr 04 '12 19:04 fgiasson

.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.

creage avatar Apr 05 '12 18:04 creage

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?

fgiasson avatar Apr 05 '12 19:04 fgiasson

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

exside avatar Apr 25 '13 15:04 exside

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

fgiasson avatar May 01 '13 13:05 fgiasson