Geecon – Modular Javascript
This session was led by two Javascript developers – Sander Mak, Paul Bakker - who presented several possibilities how to make Javascript modular.
There were usually only few lines of Javascript code in the page in the past. By the time Javascript is becoming more and more important and huge portion of the code is currently written in Javascript. As a developer I know that it is important to split your code into the separate independent parts – modules. Javascript wasn’t created in the way which is suitable for this purpose. But developers are clever people and they had found out the ways how to do this.
Three possibilities were presented here:
- Asynchronous Module Definition (AMD)
- CommonJS
- ES6 Harmony
Asynchronous Module Definition
AMD is specification for mechanism which allows modules to be loaded asynchronously. It is possible to declare dependecies between modules and thus only required modules are loaded. This is basically intended to be used on the client side of the application. One of the best known implementations is RequireJS (http://requirejs.org). RequireJS conforms to AMD specification but it contains even something more. There is optimizer which merges required modules into one file (minimized). By this way downloading of the Javascript code is faster.
CommonJS
This specifies ecosystem for Javascript but on the server side (for example on NodeJS server). CommonJS wasn’t in the scope of the presentation.
ES6 Harmony
ES6 Harmony is specification of the new Javascript version. It introduces modules mechanism. There is currently no Javascript implementation of the ES6, but there are several compilers which translates ES6 script to common Javascript. For example Traceur and CoffeeScript.
Posted in programming
Leave a Reply