Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ES6 will the module lead to multiple network calls as 2 modules cannot be defined in single file

In ES6 each module is defined in its own file.

Does that mean that we will have to do multiple network calls for each javascript module if we go the es6 way?

Is there anyway to concatenate the module files essentially create one minified javascript file for the app in es6?

We can transpile the es6 code to es5 and concatenate the same.

But, without transpiling to es5, does it mean that to use modules, we won't be able to concatenate and minify all javascript files into one?

like image 897
Nehal Damania Avatar asked Apr 08 '15 03:04

Nehal Damania


People also ask

How do ES6 modules work?

A module organizes a related set of JavaScript code. A module can contain variables and functions. A module is nothing more than a chunk of JavaScript code written in a file. By default, variables and functions of a module are not available for use.

How many parts are there in an ES6 module?

The ES6 module standard has two parts: Declarative syntax (for importing and exporting) Programmatic loader API: to configure how modules are loaded and to conditionally load modules.

Should you use ES6 modules?

Although usage of ES6 is recommended since it should be advantageous when native support from browsers released. The reason being, you can import partials from one file while with CommonJS you have to require all of the file.

Are ES6 modules asynchronous?

ES6 uses import and export. This means you only load the modules that you need, and the importing of the modules is asynchronous.


1 Answers

Bundling is the way to go.

Modern web applications consist of many, often small, modules. Loading those modules over HTTP impacts performance negatively, because a separate request is needed for each. Therefore, bundling multiple modules as a single file has a long tradition in the web development world. Current approaches are complex and error-prone and only work for JavaScript. Therefore, the W3C Technical Architecture Group is working on a new approach: Arbitrarily nested directories are archived as a single package file. Browsers access files in the package via a new kind of URL:

url-for-package SEPARATOR path-inside-package

Source: http://www.2ality.com/2013/11/es6-modules-browsers.html

like image 87
André Pena Avatar answered Sep 18 '22 19:09

André Pena