Skip to content

Commit

Permalink
Switch to express-minify.
Browse files Browse the repository at this point in the history
Note that I can't find a way for the SRI hashes to work for the minified files.
  • Loading branch information
XhmikosR committed Dec 4, 2018
1 parent 0063ef1 commit 623e850
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
10 changes: 10 additions & 0 deletions app.js
Expand Up @@ -18,6 +18,7 @@ const STATIC_OPTS = {
// middleware
const compression = require('compression');
const favicon = require('serve-favicon');
const minify = require('express-minify');
const logger = require('morgan');
const errorHandler = require('errorhandler');
const enforce = require('express-sslify');
Expand Down Expand Up @@ -86,6 +87,9 @@ if (NODE_ENV === 'production') {

// middleware
app.use(compression());
if (NODE_ENV === 'production') {
app.use(minify());
}
app.use(staticify.middleware);

app.use(favicon(path.join(PUBLIC_DIR, config.favicon.uri), '7d'));
Expand All @@ -107,6 +111,12 @@ app.use((req, res, next) => {

res.locals.nonce = nonce;

// Don't minify files that are already minified
if (/\.min(\..{7})?\.(css|js)$/.test(req.url)) {
res.minifyOptions = res.minifyOptions || {};
res.minifyOptions.minify = false;
}

next();
});

Expand Down
14 changes: 11 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -39,6 +39,7 @@
"cross-env": "^5.2.0",
"errorhandler": "^1.5.0",
"express": "^4.16.4",
"express-minify": "^1.0.0",
"express-sitemap": "^1.8.0",
"express-sslify": "^1.2.0",
"helmet": "^3.15.0",
Expand Down
6 changes: 0 additions & 6 deletions views/_partials/loadjs.pug
Expand Up @@ -4,21 +4,15 @@
var jquery = config.javascript.find((file) => file.name === 'jquery');
var clipboardjs = config.javascript.find((file) => file.name === 'clipboardjs');
var clipboardjsUri = getVersionedPath(clipboardjs.uri);
var clipboardjsSri = generateSRI(clipboardjs.uri);
var mainJs = config.javascript.find((file) => file.name === 'main');
var mainJsUri = getVersionedPath(mainJs.uri);
var mainJsSri = generateSRI('/assets/js/main.js');
| var mainJsUri = '#{mainJsUri}';
| var clipboardjsUri = '#{clipboardjsUri}';
| var jqueryUri = '#{jquery.uri}';
| var bootstrapBundleUri = '#{bootstrap.javascriptBundle}';
|
| loadjs([clipboardjsUri, mainJsUri], 'main', {
| before: function(path, el) {
| el.integrity = path === mainJsUri ? '#{mainJsSri}' : '#{clipboardjsSri}';
| el.crossOrigin = 'anonymous';
| },
| async: false
| });
| loadjs([jqueryUri, bootstrapBundleUri], 'jquery', {
Expand Down

0 comments on commit 623e850

Please sign in to comment.