amp-toolbox icon indicating copy to clipboard operation
amp-toolbox copied to clipboard

Enable minification on optimizer-express/demo/proxy.js

Open eduardogoncalves opened this issue 5 years ago • 4 comments

Hello, I need some help on enabling minification on https://github.com/ampproject/amp-toolbox/blob/master/packages/optimizer-express/demo/proxy.js I tried to use html-minifier with a customTransformer, Middleware, but can't make it works.

I want to use this options from html-minifier:

const minify = require('html-minifier').minify;
minify(content, {
    collapseWhitespace: true,
    minifyCSS: true,
    removeComments: true,
  });

I also tried https://www.npmjs.com/package/express-minify-html as suggested by @torch2424 on slack

eduardogoncalves avatar Mar 01 '19 20:03 eduardogoncalves

/ping @sebastianbenz

eduardogoncalves avatar Mar 01 '19 23:03 eduardogoncalves

Yeah, seems like there's no straightforward way to add this. This is most likely a consequence of how we've implemented the middleware @andreban will know more about this. However, we should implement basic minification as part of the transformation (remove comment, remove whitespace).

As a workaround for now, I'd suggest not using the middleware, but invoking the optimizer directly in a request handler.

sebastianbenz avatar Mar 04 '19 09:03 sebastianbenz

Any updates on this?

eduardogoncalves avatar Jan 20 '20 12:01 eduardogoncalves

Partially, #576 adds support for collapsing whitespace and CSS is already minified. The only missing part is removing comments.

sebastianbenz avatar Jan 21 '20 19:01 sebastianbenz