Is there a tool to optimize third-party libraries like jQuery and Bootstrap?

I’ve known for a while that one of my bad developer habits is using libraries like jQuery because it’s easier to remember the syntax, but then not using 90% of the features of that library. For example, using jQuery selectors and maybe a few array or object methods, but not much else.

Is there a tool that will go through the full jQuery library and filter out all the stuff I’m not using so that users don’t have to download code that’s not being used?

I suppose if there isn’t such a thing already, I may have found my first coding project. :wink:

jQuery in particular is pretty small, so I wouldn’t worry too much about using it. The next time you’re reaching for that 10% of features you frequently use, check out YouMightNotNeedjQuery. The chances are good you can get away with not using it.

Many libraries will offer some sort of tool that lets you customize the download so you can work with just a fraction of the size. Bootstrap has such a thing on their site. As far as I know, there’s no general utility for doing this to your code after it’s written, and I’d argue that’s because it’s 1) really, really hard to do, 2) a really bad idea (since it’s so hard to do), and 3) largely unnecessary. If you’re concerned about download times, you ought to import your libraries through a well-known CDN, which will not only have the needed files cached on the closest server to the user, but will also allow the user’s browser to cache files for use between sites.

2 Likes