Different types of isomorphic JavaScript modules

Modules are sections of code within a file that carry out a particular operation when called by a larger application. A module can be a single function or collection of related functions. 

Modules enable you to divide up your code into more manageable parts. They are commonly used to divide software applications into chunks that are responsible for a single or a few related tasks.

Importing and exporting keywords in an isomorphic JavaScript module

In the isomorphic JavaScript module, you can import and export keywords that allow code to pass and receive features between various libraries. To do this you:

  • Use the export keyword to make a local variable, method, class, or object available to other modules. 
  • It’s released to the public as a freely used code.
  • The developer uses the import keyword to access the public code from another module.

Types of isomorphic JavaScript modules

Isomorphic JavaScript can function in a variety of environments. Client-side in the browser with DOM and AJAX, server-side with node.js, mobile with Cordova or PhoneGap, and as a microcontroller with Espruino. These are all examples of environment-specific features, and all of the environments share one common feature: they are JavaScript-friendly. 

Experts like Spike Brehm point out that there are two types of isomorphic JavaScript modules. They can either be environment agnostic modules or shimmed per environment modules.

Environment agnostic modules

These modules solely use the capability that is native to JavaScript, and they do not use any environment-specific characteristics such as windows or processes. Lodash, async, moment.js, numeral.js, and math.js are examples of such libraries.

Modules shimmed per environment

Modules that are shimmed per environment provide just one application programming interface (API) but several implementations depending on the environment. Superagent, socket.io, debug, and PubNub are all good examples of shimmed per environment modules.

Modules that are environment-independent function flawlessly in every setting. Shimmed modules, however, require the surrounding environment to choose the appropriate implementation. When an application utilizes the module, this does not present a problem. The environment in which the application will operate, such as the server or client, is obvious. But the proper implementation cannot be taken if the module is being used by another module that’s already in use. 

An example of this is a library that performs currency conversions by sending network queries to a REST API. A library that uses an appropriate debug library is another good example. The module that does the consumption will also distribute implementations for the various environments. This causes an effect known as cascade, which forces all modules farther down the chain to make builds for multiple settings.

Final word on different types of isomorphic JavaScript modules

Now you know how the two types of isomorphic JavaScript modules function, how they are similar and how they are different. Which module is going to work the best will depend on what is using the module and the environment it’s in.

If you’re looking for SEO project management software to better manage your workflow, clients, and business – evisio.co is your solution. Try evisio.co for free here!

Start using evisio today at no cost.

Complete access without commitment.

Start for Free

What evisio is all about

Evisio helps agencies, marketers, and SEO consultants get results, no matter their level of SEO knowledge. It takes the guesswork out of SEO by telling you exactly what to do to improve your rankings and makes SEO simple by bringing all the parts of your SEO process together in one place.