Skip to content

Laravel 5 5.1 HTML Minifying

Trevor Fitzgerald edited this page Jun 23, 2015 · 6 revisions

I recommend using Gulp, instead of a PHP package, to compress the HTML that gets generated by your Blade template files. It works very well and is very configurable. It uses gulp-htmlmin, which uses html-minifier.

Create a new task in your gulpfile.js

var htmlmin = require('gulp-htmlmin');

gulp.task('compress', function() {
    var opts = {
        collapseWhitespace:    true,
        removeAttributeQuotes: true,
        removeComments:        true,
        minifyJS:              true
    };

    return gulp.src('./storage/framework/views/**/*')
               .pipe(htmlmin(opts))
               .pipe(gulp.dest('./storage/framework/views/'));
});

Call the gulp task

$ gulp compress

Clone this wiki locally