Hacker News new | ask | show | jobs
by TheAceOfHearts 4131 days ago
If you're using CommonJS you can do require('lodash/category/method'), and when it gets built on the frontend it'll only include the method and its dependencies. So if you're using only 5% of lodash, you'll only get that 5%.
2 comments

Right. If on node, you can also use modules via NPM ( https://www.npmjs.com/browse/keyword/lodash-modularized ).

But as I said, this is common in many frameworks. Hell, you can even do with JQuery ( http://projects.jga.me/jquery-builder/ ). So having this ability doesn't make Lodash special.

This is not presented as the preferred method to use the framework on the project page either. You just get a link on the front page to the whole shebang. Probably because most developers just download the whole thing and stick it in.

What I was really hinting at was code complexity. Sometimes having something light and small that you can stick in there without worrying about anything is useful. Lodash can address that by having a light version linked off their front page, but they haven't done that.

On top of everything, Underscore is ribbing them on this very point. See http://underscorejs.org/ and bit down "(3x smaller than Lodash ;)" in bold. Seems like a really easy point to address.

If you care about filesize, you'll probably optimize as much as possible. You can do this with Lodash using modular imports.

There's little upside in hosting a light version, and fragmenting the docs. Min/max'ing on filesize lets you save 15 kB, or 0 kB. Creating a light build that saves 5 kB is a maintenance cost with a poor ratio relative to reward.

> If you care about filesize

I don't care about filesize. I care about code complexity. The more crap you add to a page, the slower it will run. You also get a higher probability of conflicts and problems in the long run.

If you need something, you need something. But if you don't and you just throw it in there, you're asking for problems down the road.

For an example of cherry-picking lodash modules see

https://github.com/postaljs/postal.js/issues/91#issuecomment....

Just noting that CommonJS has nothing to do with this capability, it will work in any format.