177 points · by tambourine_man · 10y ago · 90 comments
cash.min.js is 7.8kb once downloaded, for anyone coming to this thread after me.
Nice work all around, is this comparable with Zepto? What features are missing from Cash that you guys hope to add?
https://github.com/kenwheeler/cash/blob/3cb498ca7c5776b8cadc...
curl https://rawgit.com/kenwheeler/cash/3cb498ca7c5776b8cadcce588... | wc -c # 9282
curl https://rawgit.com/kenwheeler/cash/3cb498ca7c5776b8cadcce588... | gzip | wc -c # 3225
curl https://cdn.jsdelivr.net/cash/1.0.0/cash.min.js | gzip | wc -c # 2636
https://github.com/finom/balalaika/
If that's too much, there's an even more extreme version (379 chars):
> document.querySelectorAll('.my-selector')
Jquery functions Zepto has that Cash does not: ajax, contents, hide/show, map, offset, offsetParent, replaceWith, scrollLeft, scrollTop, size, slice, submit, toggle, unwrap, wrap, wrapAll, wrapInner
Zepto also has some optional plugins that aren't in the default build.
Finding two unrelated projects with the same name was a kik in the pants.
Since browser compatibility is one of the primary purposes of jquery, I think it would be helpful if this library's readme said what its browser compatibility is.
var _$ = function(selector){
var els = document.querySelectorAll(selector);
return Array.prototype.slice.call(els);
}
For example: _$('span').forEach(function(el){ el.style.color = 'red' });I didnt say you should add an invisible 1MB image to your site but that a few kilobytes do not make such a difference anymore (particularly when you lose functionality at the same time).
74 kilobytes might have been a lot a few years ago, these days it is (unfortunately) mostly "noise". Particularly if it is not a real alternative but only a subset of the original functionality.
My metrics are aproximately 1:5:7 for lines of code:tests:documentation and I might do the same check later on for jquery, but from reading their source and documentation I think they might be in a similar situation.
Including jQuery in browsers is kind of a ridiculous idea...
But if you're going to argue over 5KB perhaps you shouldn't be using JavaScript or CSS. If bandwidth matters that much, plaintext should keep the punters happiest.
I never had issues with older browsers because most of those issues are css related. And imho if you need Javascript to fix your layout you are having other issues.
I still go for jquery for the likes of http requests and css selectors. Which libraries do you use for those tasks now?
(requests) https://developer.mozilla.org/en/docs/Web/API/Fetch_API http://caniuse.com/#feat=fetch
(css selectors) https://developer.mozilla.org/en-US/docs/Web/API/Document/qu... https://developer.mozilla.org/en-US/docs/Web/API/Document/qu... http://caniuse.com/#search=queryselector
Self-host this file, people.
At 3.8k gzipped, I'd just inline the minified version...
If you haven't tried writing "raw" JS in a while give it a try. You might be surprised.
$(element).is(selector)
to the standard: element.mathes(selector);[1] https://github.com/umbrellajs/umbrella/blob/master/src/plugi...
- Zepto : http://zeptojs.com/
- Umbrella JS (mine): http://umbrellajs.com/
- Nano ajax: https://github.com/yanatan16/nanoajax
It's not ready.
Maybe I'm missing something?
Facebook did a related study more recently and found that large numbers of users had cold caches (https://code.facebook.com/posts/964122680272229/web-performa...).
`Array.prototype.slice.call(document.querySelectorAll(selector)).forEach(cb)`
vs
`$(selector).each(cb)`
[0] https://developer.mozilla.org/en-US/docs/Web/API/NodeList
I found this one, but it's from 2014 so I'm not sure it's the same Cash.
Sadly, JQuery and its continued success isn't attributed to its efficiencies. It's community support, adoption, and heavy downstream reliance will keep it around as a standard for eternity.
[2] github.com/umbrellajs/umbrella
You can always check yourself [1], but of course it's not what you asked.
C3js made a good impression otherwise and flot seems to be dead (no activity on https://github.com/flot/flot, or is there a living fork?) making that decision hard.