Does uploading modules into a single file decrease app performance?

Asked

Viewed 50 times

1

My project has several modules, if I load them all into one file - modulos.js - am I decreasing the app’s performance? ex:

file that loads modules (modulos.js):

 exports.var1 = require("...")
 exports.var2 = require("...")

File 1:

    modulos = require(modulos.js)

    modulos.var1.funcao()
    modulos.var2.funcao()

File 2:

   modulos = require(modulos.js)
   modulos.var1.funcao()

1 answer

0


Loading all modules in a file or clicking on each module seems irrelevant.

Node.js memorializes each loaded module and does not reload the module if prompted again. If so N files that need a module it serves as memory.

I really advise that each file requires the modules it needs at the beginning of the file. So each module is more watertight and if you need to remove it or use it elsewhere it is easier to control its real dependencies.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.