
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
express-uglify-assets
Advanced tools
A middeware for express that concatenates and bundles your js and css files on the fly.
//add assets in our routes or in your views
assets.addJs('javascripts/library.js');
assets.addJs('javascripts/main.js');
assets.renderJs();
<!-- output in development -->
<script src="/javascripts/library.js"></script>
<script src="/javascripts/main.js"></script>
<!-- output in production -->
<script src="/04e9f94bbeb85c9f9ecb98d724cd2cc0.js"></script>
npm install express-uglify-assets --save
expressUglifyAssets([options])
var express = require('express');
var expressUglifyAssets = require('express-uglify-assets');
app.use(expressUglifyAssets({
/* all options are optional */
process: true, /* combine and minify the assets. Default: true in staging and production everywhere else false */
root: __dirname + '/public', /* path on your filesystem assets get resolved to. Default: "." */
rebaseTo: 'http://localhost:3000/' /* controls the url to which all URLs are rebased (usefull if you want to serve them over your cdn url) Default: "/" */
cleanCssOptions: { /* options that are passed to the clean-css library */
wrapAt: 100
},
uglifyJsOptions: { /* options that are passed to the uglify-es library */
output: {
max_line_len: 100
}
},
header: { /* set additional headers for the served assets */
{'Cache-Control': 'public, max-age=31557600'} /* cache for 1 year is the default in production and staging */
}
}));
The middleware adds the following functions to your template and to res.assets in your express route callback.
assets.addCss(file)
assets.renderCss([options], [namespace])
assets.addJs(file)
assets.renderJs([options], [namespace])
example with the template engline ejs
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Example assets</title>
<% assets.addCss('stylesheets/style.css'); %>
<%- assets.renderCss(); %>
</head>
<body>
<h1>asset express ejs example</h1>
<p>
On this page the css and js is minified. Go <a href="/not-minified">here</a> to see the not minified version.
</p>
<% assets.addJs('javascripts/library.js'); %>
<% assets.addJs('javascripts/main.js'); %>
<%- assets.renderJs(); %>
</body>
</html>
assets.renderJs({attr: {async: true, id: 'my_awesome_script'}});
assets.addJs('javascripts/advert.js', 'advertise');
assets.addJs('javascripts/library.js');
assets.addJs('javascripts/main.js');
assets.renderJs();
assets.renderJs({attr: {async: true}}, 'advertise');
When {process: true} is set, each asset is generated in sync the first time assets.renderJs/assets.renderCss is called. So the first page load will be slower. The minified and combined css/js is cached in memory. Subsequent calls with the same options and files will be served from memory. This also means changing the content while the server is running will not change the content. You need to restart your app. The Files are served with the header Cache-Control: public, max-age=31557600'
When {process: false} is false, what is the default in development, the files are send with express.sendFile(), so changes will be available without restarting the app.
express-uglify-assets is licensed under the MIT license.
FAQs
combines minifys js and css on the fly
The npm package express-uglify-assets receives a total of 0 weekly downloads. As such, express-uglify-assets popularity was classified as not popular.
We found that express-uglify-assets demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.