packages icon indicating copy to clipboard operation
packages copied to clipboard

Add https://github.com/js-cookie/js-cookie

Open aadrian opened this issue 8 years ago • 9 comments

Please add https://github.com/js-cookie/js-cookie

Thank you.

aadrian avatar Feb 11 '16 14:02 aadrian

@aadrian, just FYI, have you have considered using the bundled goog.net.Cookies?

ducky427 avatar Feb 11 '16 14:02 ducky427

@ducky427 of course :). But if existing projects are already using the other API, there's not always the possibility (or the budget yet) to rewrite stuff :).

aadrian avatar Feb 11 '16 14:02 aadrian

agreed. that makes sense.

ducky427 avatar Feb 11 '16 14:02 ducky427

FWIW, even if the application is new, generally there is no benefit in changing the module for the other one. js-cookie is simpler, does not limit characters (accepts anything in the utf-8 range, by default using rfc 6265 for encoding), is probably smaller, have a better documentation to prevent abstraction leaks (even for server-side) and allows converting the values into another representation to match server side incompatibilities (among other things)

FagnerMartinsBrack avatar Feb 11 '16 21:02 FagnerMartinsBrack

While other points are probably true, I doubt js-cookie is smaller.

In general Closure libraries result in smaller result because Closure compiler can do dead code elimination and inlining etc. for them. Such whole program optimizations are not possible with foreign libs (cljsjs).

Deraen avatar Feb 12 '16 07:02 Deraen

Could you point a link where net.Cookies minified and gzipped is less than 900 bytes?

FagnerMartinsBrack avatar Feb 12 '16 09:02 FagnerMartinsBrack

@FagnerMartinsBrack it doesn't matter if it's less than 900 bytes, it's exactly the size of the stuff you'll use and compressed in the most advanced way possible.

Just taking the goog.net.Cookies namespace, stripping comments and removing whitespace, gzipping gets me to 1084 bytes. with all names shortened by advanced compilation you're easily below 900 bytes. (And this assumes you're using every function provided.)

martinklepsch avatar Feb 12 '16 09:02 martinklepsch

(ns cookie-test.core
  (:require [goog.net.cookies :refer [cookies]]))

(.set cookies "name" "value")

(js/console.log (.get cookies "name"))

And the resulting advanced compiled file is 1.9KB, gziped 1.2KB. But that file contains general ClojureScript stuff which is present in every Cljs build. The cookie related code is something like 1.1KB and gziped 600B.

To try this yourself you can use mies template: lein new mies cookie-test

Deraen avatar Feb 12 '16 09:02 Deraen

@Deraen Sorry for my ignorance, but I didn't understand the code you posted. I just got really curious about the code size.

Thinking again it makes sense to be smaller because in js-cookie we accept any character in the cookie name or value, therefore we have the need to hardcode the character codes that we need to ignore from encodeURIComponent and decodeURIComponent so we don't have to rewrite the whole percent-encoding algorithm (here is a Java example of what I am talking and here is the hardcoded codes that I was talking about). Because of this, the data cannot be minified or gzipped properly.

Anyway, thank you very much for taking the time to respond :+1:

FagnerMartinsBrack avatar Feb 12 '16 11:02 FagnerMartinsBrack