Skip to content

Instantly share code, notes, and snippets.

@DamonOehlman DamonOehlman/
Last active Dec 23, 2015

What would you like to do?
The words behind the #sydjs rant (which went a little too quick - I'm not giving up on the concept yet) for my rant about creating modules that can be selectively required.

Write your Javascript libraries the right size.

JS modules and libraries tend to be either too large or too small.

Driven by arbitrary constraints or poor engineering and/or decision making.

I want my application size to be optimal, and I want to be able to tell friends about cool libraries I've found.

In the old days (jQuery) telling people about stuff was easy, but optimal size wasn't.

Now in the post microJS era, optimal size is achievable (not necessarily easy) but telling people about stuff can be hard.

Using technologies like browserify and targeted require statements you can do some cool things.

You can do the same thing with other module systems too.

So, write libraries and modules that can be used selectively. Not specifically micro.

So how exactly do you do this?

If you are using browserify then separate useful functionality at the file level and include at the top-level of your module.

- foo
|- package.json
|- index.js
|- bar.js
var bar = require('foo/bar');

A good example of doing this in the wild is

When should you consider breaking out?

If a sub-component has additional dependencies to the rest of the package.

If you believe a sub-component should be versioned separately.

Also micro libraries with strong conceptual boundaries are ok too. Eve and Keymaster come to mind.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.