Does compressing all Nodejs JS files (node_modules) decrease performance?

Asked

Viewed 451 times

1

In my application I am using Gulp to compress all my files JS inside the case node_modules, my question is on performance, it is a bad practice to do this or not?

If you have any suggestions will help a lot!

  • 1

    Reading a compressed js file is always faster. Now, you will serve all the files of your Node modules along with your application? The interesting thing is to minify the production files. I do not know if compacting the development ones would bring any benefit, except for the execution of their tasks...

  • 1

    One question, why are you compressing node_modules files? Question of deploy? Modules you install via NPM (which are inside the node_modules folder) should not be touched.

  • I’m not moving, it’s a question of structure. The module folder is outside the folder that goes to production (public) and I need to bring all the Javascript dependencies inside it, an alternative that I thought is to copy everything using Gulp.

1 answer

1

There are several ways to work with the dependencies of modules installed via NPM.

Compressing all node_modules and deploying it is never a good option. Making reference in your direct project to node_modules is not a good practice for several reasons, some of them are:

  1. Some library can be updated via NPM and break your application
  2. You will be compressing many files atoa, then within node_modules not only has the library you use, without the Prod version (not minified) has the Developer version (minified) has test scripts, geralmetne README files etc etc.

A good practice is.

You have the following structure (for example)

node_modules/
----- angularjs/
---------- angular.js
---------- angular.min.js
---------- vários outros arquivos

Your app here

app/
----- js/
---------- libs/
--------------- develop/
-------------------- angular.js (aqui é o módulo do angular instalado via NPM sem ser minificadom usado geralmente para debug ou olhar o código para entender o que a library faz)
dist /
(dentro da pasta dist que seus arquivos vão estar todos minificados, otimizados e compactados)

You can make this copy via GULP, GRUNT or even manually if you prefer.

So also use GULP or GRUNT to minify the js files, (meuarquivojs.min.js) to deploy to the server.

The good thing about this practice is if you wanted to update some module, you can compare via any merge tool (Winmerge for example) and see what has actually been updated or changed with respect to what you are using.

So you can update the modules without fear, as they do not impact directly on your application unless you choose to update them consciously.

Anyway, never delpoy the node_modules folder.

Browser other questions tagged

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