SO WAIT... HOW DOES THIS WORK?
I'm glad you asked!
Async Module Definition (AMD)
We request that eventbrite.com/.../static/js/split.js be on the page first.
Define Takes 3 Arguments
But typically the "name", argument 1 is guessed when it is loaded.
AMD, Can be Problematic Though
Now we need to make sure when we add a dependency that we don't accidentally break anything. This moderately increases our WTF ratio.
Enter CommonJS Style Syntax
Still, async, but now with better syntax.
requirejs runs .toString() on functions and discovers deps
Note: It isn't completely abiding by commonjs standards. It is just looks a bit closer.
Tangent: CommonJS
Comes from Node.js. We use it in our grunt tasks.
Differences:
- No outer function
- Explicit exporting instead of a "return"
- It is synchronous thus a build is required for client side
- Async takes effort
Tangent 2: Handlebars Templates
We no longer need templates/bundle.yaml
You can now just: