I have just finished reading this article on Javascript modules. I can understand that CommonJS modules are synchronously loaded while AMD modules are asynchronously loaded.
What I don't understand is that how can I module become magically synchronous if I write it in the CommonJS format, or how it becomes magically async if I write it in the AMD format. I mean javascript does not have a define
or require
keyword even. All they are are specs not libraries.
I mean the behaviour of module loading is dependent on the module loader and not how the module is structured. And if that is the case why follow a coding pattern for different types of modules ?
Am I right in assuming that all libraries in the NodeJS world are synchronously loaded, regardless in what format they are written. And all modules in the browser space is asynchronously loaded.
If my above assumption is correct then why is there even a spec for UMD ? I mean if a script loads based on the environment it is present in then why make a spec for universal module loading ?
Can someone help me with this confusion ?