Minifcar. JS and CSS files in bulk

Asked

Viewed 340 times

1

Guys, I wonder if you know any tool capable of minifying files on js and css in bulk, are several files in a main folder spread in hundreds of subfolders, I am using Node.js where I have several modules in these subfolders, and would like to minify the possible files in order to improve the final processing of the app.

  • 1

    Do you want to minify files for Node.JS? I’m not sure that makes sense. Minification is done to reduce files in order to reduce the size of HTTP messages on a website. With Node these files are not loaded via HTTP.

  • 1

    So, I do want to minificar for Node.JS and yes, it would help me, Node takes a while to unzip the package, in this package is the system as for example images, js and css, currently my modules folder is with 40 megas this because it has several javascript files, i managing to minify and taking the comments in js, I will be able to reduce the processing time to start my app, currently it takes about 20 seconds to start, reducing the size of the files consequently improve the performance.

1 answer

3

It depends on which web framework is using with Node.js, if it is Express (the most common) there are the:

express-Minify

To install use:

npm install express-minify

It combines everything in and sends to the request reply:

app.use(minify());
app.use(express.static(__dirname + '/static'));
app.get('/tudo.min.js', function(req, res)
{
    res.setHeader('Content-Type', 'application/javascript');
    res.end(responseJS);
});

You could order like this: <script src="/tudo.min.js"></script>, it also has caching of this combined version of the files:

express-Minify-plus

Is a modification of express-minify, to install use:

npm i express-minify-plus
  • 1

    Opa, I will make a test, but I do not know if it will work in my case, since the modules communicate using paths, but I will make the test to see if this is it.

  • @Patrique "paths" should be the routes that refers to the Express right? If the case is easy, use the app.get as in the example I posted ;)

Browser other questions tagged

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