Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minify HTML #220

Closed
adamduncan opened this issue Jun 22, 2021 · 1 comment · Fixed by #224
Closed

Minify HTML #220

adamduncan opened this issue Jun 22, 2021 · 1 comment · Fixed by #224
Assignees

Comments

@adamduncan
Copy link
Collaborator

adamduncan commented Jun 22, 2021

Minify all HTML output files as part of 11ty build config.

E.g. from this reference, or from one of our other 11ty sites:

const htmlmin = require('html-minifier');
  
 //...

    eleventyConfig.addTransform('htmlmin', (content, outputPath) => {
      if (outputPath.endsWith('.html')) {
        let minified = htmlmin.minify(content, {
          collapseWhitespace: true,
          minifyCSS: true,
          minifyJS: true,
          removeComments: true
        });
        return minified;
      }
      return content;
    });

Suggest we perhaps do this for all environments, as opposed to just for production, just to get a better steer on any potential pitfalls or minification quirks during development.

This will boost TTFB of responses for the inital load of HTML pages. For example, the homepage should go from 17kb to 14kb. Every lil' helps on that first request.

@Pete-Robelou
Copy link
Collaborator

Done.

I was a little unsure about running it locally for dev as it could slow things down as it builds but I didn't notice any perceivable difference 🙂

@Pete-Robelou Pete-Robelou linked a pull request Jun 22, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants