• 16 Posts
  • 159 Comments
Joined 1 year ago
cake
Cake day: June 10th, 2023

help-circle















  • A few things to note:

    JavaScript is not a “batteries included” language - if you need math functions or cryptography or any kind of utility, you need to load it along with your script (usually from npm).

    Loading a lot of small files is slower than streaming one big combined file, so tools like webpack will stitch all the files in your node_modules directory and minify it, so it’s not unusual to have big files like this.

    Does the site actually need all this code? Probably not! The ridiculous part is that every one of those npm dependencies has it’s own list of dependencies, so just grabbing a small handful of libraries can result in huge trees of files!

    Even more insane is that many of these probably have shared dependencies, but very slightly different versions, so multiple almost identical packages get downloaded.

    Worst of all is that is most packages probably don’t use 90% of the code in the dependencies that they do need - e.g. if you want a “sin” function from a math library then you’ll be downloading “cos” and “tan” too.

    There are tools like tree-shaking and pruning that help to remove unused packages during the bundler step, but I rarely see them used. It’s a lot of extra configuration and setup when mostly the products aren’t affected by a few extra KB or MB.

    Anyway that’s why js and node and npm suck to both work with and to use. The site probably doesn’t need all that extra code, but there is no easy way to prove it so you get everything “just in case”.