I am ready with an Express-generator sccafold website and need to publish it. Which command should I use to minify files and be optimized for publishing? And also, what are the directories should I take to upload?
Caching is one of the common ways of improving the Node Js performance. Caching can be done for both client-side and server-side web applications. However, server-side caching is the most preferred choice for Node Js performance optimization because it has JavaScript, CSS sheets, HTML pages, etc.
Since node. js runs on the server, I'd say it's meaningless to minify the code.
express-generator is a server rendering framework based on express framework, not a client side rendering like react, vue, angular, etc in which a minify process is very common.
This question: Does it make sense to minify code used in NodeJS? indicates me that nodejs is already performing optimizations for nodejs code.
So, if we are are talking about express app, just a static files are candidates to minify to improve performance.
In this case, you could perform a manually build process for your production environment like client side frameworks(react, angular, vue, etc) does
Check this library: express-minify at which we can minify several types of files:
app.use(minify({
cache: false,
uglifyJsModule: null,
errorHandler: null,
jsMatch: /javascript/,
cssMatch: /css/,
jsonMatch: /json/,
sassMatch: /scss/,
lessMatch: /less/,
stylusMatch: /stylus/,
coffeeScriptMatch: /coffeescript/,
}));
In this case you could use this library uglify-js but you will need a strategy to keep this optimized files in a temp folder like build, dist, etc like client side rendering frameworks (react, vue, etc) does
You could do something like this:
if(process.env.NODE_ENV==='PRODUCTION'){
app.use(express.static(__dirname + '/static-optimized'));
}else{
app.use(express.static(__dirname + '/static'));
}
And finally execute the minify process over each file:
uglifyjs ./static/my-code.js --output ./static-optimized/my-code.min.js
To avoid manual process, you can write a routine to iterate all js files and execute uglifyjs one by one. This could be your build script in your package.json
From: https://stackabuse.com/6-easy-ways-to-speed-up-express/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With