# How to compress the generated HTML files?

**URL:** <https://talk.jekyllrb.com/t/how-to-compress-the-generated-html-files/8035>\
**Category:** Uncategorized\
**Created:** [February 20, 2023, 2:58am UTC](https://talk.jekyllrb.com/t/how-to-compress-the-generated-html-files/8035 "2023-02-20T02:58:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccmywish](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/ccmywish/32/5008_2.png) [@ccmywish](https://talk.jekyllrb.com/u/ccmywish)\
**Post date:** [February 20, 2023, 2:58am UTC](https://talk.jekyllrb.com/t/how-to-compress-the-generated-html-files/8035/1 "2023-02-20T02:58:55Z")

</div>

I notice that all my generated files are not compressed. And there still exist comments not deleted.

Even though I make the env var `JEKYLL_ENV` to production, still no effect. So how do I delete all comments in generated HTML files (and get compressed)

---

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [February 20, 2023, 6:33am UTC](https://talk.jekyllrb.com/t/how-to-compress-the-generated-html-files/8035/2 "2023-02-20T06:33:37Z")

</div>

Jekyll by itself does not compress. However, consider basing your layouts on this: [http://jch.penibelst.de](http://jch.penibelst.de)  
Works well, though does not play nice with `//`-style comments in JavaScript; need to convert to  
`/* … */`.  
One more thing: If you’re using Sass, config like so:

```auto
sass:
  style: compressed # minification of compiled CSS

```

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [February 21, 2023, 5:13am UTC](https://talk.jekyllrb.com/t/how-to-compress-the-generated-html-files/8035/3 "2023-02-21T05:13:18Z")

</div>

you can use a node package to do it - html-minifier. Or Gulp tasks can do the same type of thing. Not sure about the comments, that is probably an option.

I use AWS amplify for a site and have that along with some other stuff minifying things, here is my package.json file.

```auto
{
  "name": "jekyll-amplify",
  "version": "1.0.0",
  "description": "",
  "main": "",
  "dependencies": {
    "autoprefixer": "^10.0.2",
    "html-minifier": "^4.0.0",
    "htmlhint": "^0.14.2",
    "postcss": "^8.1.8",
    "postcss-cli": "^8.3.0",
    "uglifyjs-folder": "^2.0.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build:jekyll": "jekyll b",
    "postbuild:jekyll": " npm run htmlhint || exit 0",
    "css:autoprefixer": "postcss -u autoprefixer -r --no-map _site/assets/css/site.css",
    "minify:html": "html-minifier --input-dir _site --output-dir _site --remove-comments --collapse-whitespace --file-ext html",
    "minify:js": "uglifyjs-folder _site/assets/js/ -e -x .js -o _site/assets/js/",
    "htmlhint": "npx htmlhint \"_site/**/*.html\"",
    "deploy": "npm run build:jekyll",
    "postdeploy": "npm run minify:html && npm run minify:js && npm run css:autoprefixer"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "homepage": ""
}

```

if you have node installed, you could add this to your project directory and then do `npm i ` to install the dependencies and then `npm run deploy` should build your site and miniize all the things. Assuming you have paths setup like I do.

If you are not familiar with node then I probably wouldn’t recommend doing this.

---

<div class="post-metadata">

**Author:** ![Koos](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@Koos](https://talk.jekyllrb.com/u/Koos)\
**Post date:** [March 1, 2023, 8:44am UTC](https://talk.jekyllrb.com/t/how-to-compress-the-generated-html-files/8035/4 "2023-03-01T08:44:06Z")

</div>

Not answering your question directly, but I went back and forth on minification a few times. My best experience was with using the minification of the CDN one of my sites is using. But that one also didn’t handle Alpine shorthand well (`@click=""` `:class=""`). Then I just search/replaced most of my HTML comments with Liquid comments (`{% comment %}`). I also use dashes more often: `{%- -%}`, to remove the leading and trailing spaces.

With GZIP enabled on the server, the remaining spaces really don’t impact performance.
