O'Reilly logo

Continuous Integration, Delivery, and Deployment by Sander Rossel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Minifying HTML

First, let's start with minifying our HTML. There are various plugins you can use, but we will use HTML Minifier (https://www.npmjs.com/package/html-minifier). We will need the Gulp plugin, which will also install HTML Minifier (https://github.com/jonschlinkert/gulp-htmlmin):

npm install gulp-htmlmin --save-dev

The usage is quite simple:

var htmlmin = require('gulp-htmlmin');gulp.task('minify-html', function() {   return gulp.src(['index.html', 'views/*.html'])      .pipe(htmlmin({         collapseWhitespace: true      }))      .pipe(gulp.dest('prod'));});

The possible options can be found in the HTML Minifier documentation. Beware some options: they may break your page. For example, some libraries, such as Knockout.js, can depend on comments, but ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required