-2

Is it possible to import a javascript file to another javascript file, just like we import sass files?

This question might have been masked as a duplicate to some other question. But it is not because I know that we can concat two or more JavaScript files.

But I looking for a better. I like the idea of importing files in sass (I am looking for the same process, in JavaScript).

As it will also help to send only 1 request to the server.

Community
  • 1
  • 1
Yashu Mittal
  • 1,478
  • 3
  • 14
  • 32

1 Answers1

0

You can use require.js or node export and import syntax. But you'll have to write ES6 JavaScript Code which is the next version to support import and export statements. Using a transpiler such as babel you can compile those ES6 code to ES5 which browser understands.

Read more about ES6 module system and babel here. https://babeljs.io/learn-es2015/#ecmascript-2015-features-modules

Thusitha
  • 3,393
  • 3
  • 21
  • 33