-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CommonJS modules with Vaccine #41
Conversation
This is probably excessive and maybe undesired, but hey it saves ten bytes... and it means package.json doesn't have to be built. This also means that crossfilter loses it's "version" property in node. I'm not sure how problematic that is.
I reduced the size even further by renaming the The next commit removes |
This last commit doesn't change |
Interesting, thanks. Since Crossfilter already works fine in both browsers and Node.js, I’m not convinced there’s any reason to change anything here. |
I converted crossfilter to CommonJS format, and then included vaccine so it could work in the browser. Vaccine is a super-simple and small-size way to get modular JavaScript. It also lets applications (or libraries) require libaries (
require('crossfilter')
).Right now, all the info on vaccine is on the README, but I will be making a blog post in the future to explain the benefits of vaccine compared to other modules-in-the-browser solutions.
I did this partly as an exercise to see the before and after size differences, but also because I will probably be working with the crossfilter code in conjunction with my work on DataZooka.
At first, I tried to keep the changes as small as possible (83 insertions, 56 deletions in the source files in this commit). Then, I went ahead and made a lot of changes to how the modules are grouped. Just drop or change that commit if you don't like how it's done.
The advantages to this change are the removal of global variables, a familar module format (CommonJS), and that now the actual source files can be used in a Node.js environment. I didn't make this change, but the test files could require the individual modules, instead of relying on the crossfilter global, if desired.
The disadvantage is that this adds some size to the library.
Minified and gzipped sizes:
I initally used vaccine_ordered.js. For the direct translation commit, this added 569 bytes (17.8%) from the base commit. Then I created a specially-made
vaccine.js
to reduce the size (I'm actually thinking of making it one of the default configurations). This saved 114 bytes (3.6%).Also, note that more of the added bytes are caused from converting to CommonJS format, than from including
vaccine.js
: