JavaScript Module Loaders Considered Harmful
techblog.ironfroggy.com
JavaScript Module Loaders Considered Harmful
1–10 of 45 posts
Re: JavaScript Module Loaders Considered Harmful
#2Point 1: You will almost always be transpiling your javascript. In any serious project, you will want to have lots of small files to ease development, and then concatenate into larger files to ensure optimal http loading. If you don't already do this regardless of modules, you probably should.
Point 2: If you are intentionally or serendipitously relying on script execution order, that is your bug. The module loader has helpfully exposed a bug in your code for you.
Point 3: If you have lots of modules, it is simpler to deal with a module system than mashing together a load of scripts.
This complaint should come with a severe disclaimer that it only applies to trivial applications, because as soon as you start building something complicated the arguments are just plain wrong.
Software engineering is hard, and robust software engineering practices usually only pay off once you get beyond trivial examples. The ones that work, however, pay off massively once you do use them for more complex use cases.
Re: JavaScript Module Loaders Considered Harmful
#3Ad #1, maybe my projects have been too small, but I never felt lost even when using CoffeeScript as the source. I mean I can see in the comment above the module which file it relates to.
Ad #2, not sure this applies to CommonJS.
Ad #3, there are really just 2 standards. Not sure that just saying what the heck, I'll just use the global `window` object is a better solution when trying to integrate multiple different vendor libraries and your code.
Re: JavaScript Module Loaders Considered Harmful
#4All of the issues in #1 and #3 don't actually come from modules, but from "doing it wrong" -- preprocessors and forced dependencies and all the other bad practices that have been tacked on top.
Re: JavaScript Module Loaders Considered Harmful
#5Re: JavaScript Module Loaders Considered Harmful
#6These complaints ring true for trivial javascript projects, however if you are building complex javascript heavy applications the equation quickly changes. Point 1: You will almost always be transpiling your javascript. In any serious project, you will want to have lots of small files to ease development, and then concatenate into larger files to ensure optimal http loading. If you don't already do this regardless of…
Re: JavaScript Module Loaders Considered Harmful
#7Re: JavaScript Module Loaders Considered Harmful
#8These complaints ring true for trivial javascript projects, however if you are building complex javascript heavy applications the equation quickly changes. Point 1: You will almost always be transpiling your javascript. In any serious project, you will want to have lots of small files to ease development, and then concatenate into larger files to ensure optimal http loading. If you don't already do this regardless of…
For those devs, like myself, who are unfamiliar with large javascript projects, do you have a link to an open-source javascript-heavy project that fits your points?
Re: JavaScript Module Loaders Considered Harmful
#9When I looked up for some wrapper to Backbone I came across ChaplinJS: https://github.com/chaplinjs/chaplin/ and it was nice, but using the module system was a nightmare. It was so painful, that I forked it and remove the module system from the code (which was a pain, but still less painful than handling the module system). the fork is here: https://github.com/snird/Mildred and I use it in production now.
Re: JavaScript Module Loaders Considered Harmful
#10What are the supposed benefits of using module loaders over say minifying and concatenating all your JS into one maybe two files which are then placed in script tags at the bottom of your HTML?
- Explicit dependencies (instead of using the global scope for communication)
- Easier to reason about and test parts of the code
- Errors are properly isolated in a module
The post is putting module loaders (requirejs) and "using modules" (e.g. commonjs) into the same box. With browserify you end up with one or maybe two large concatenated file that you then place in script tags at the bottom of your HTML. There's no "instead".