how to compress and minify assets using jekyll plugins
Asked Answered
B

6

18

I have a simple test jekyll app like so:

index.html is:

<script type="text/javascript" src="/assets/myfile.js"><script>
<p>hi</p>

and the myfile.js files is as follows:

var  x  = "this is a string";
alert(x +  "hi");

I just want to add a plugin so that it can minify the js file before it is written to the _site/assets/myfile.js file

How can i achienve that?

Boletus answered 18/4, 2012 at 11:34 Comment(0)
B
15

Here's a summary of what I've found while solving this in 2014:

Started with

  1. https://github.com/donaldducky/jekyll-cssminify

    Development was going well until it was beat by this project:

  2. http://www.matthodan.com/2012/11/22/jekyll-asset-pipeline.html

    ...which so far has been my favorite to implement, except it doesn't work now and it looks like development has been halted, so I was forced to turn to

  3. https://github.com/envygeeks/jekyll-assets

    ...which again, beats #2 but is just a touch trickier to use. Anyway, that's the only one that works, so that's what I'm using now.

Bessie answered 25/2, 2014 at 22:6 Comment(4)
Another +1 for jekyll-assetsEdvard
Stupid question: how to use jekyll-assets to compress JS? I'm new to Jekyll and its docs sucks.Retch
Hi @rilwis, no worries. Been a while since I worked on this but it looks like right on the readme for Jekyll Assets there's a JS configuration object with a compression flag: github.com/jekyll/jekyll-assets#configurationBessie
I come from the future and unfortunately jekyll-assets' development stopped in 2020.Overnight
T
5

There are plugins for HTML and CSS minification with Jekyll, but a search doesn't turn up anything obvious for JS.

However, the source for CSS one above is less than 100 lines and actually uses Juicer to do the minification, which can also do JS, so that plugin could easily be used as a template to implement your own JS minifier (it looks like even just s/css/js/g would be close to working).

Tallis answered 19/4, 2012 at 11:36 Comment(0)
L
4

I recommend the Jekyll Asset Pipeline gem for this. It supports any language (e.g. Scss, Less, CoffeeScript, Erb, etc.) and has a bunch of features (e.g. asset tagging, compression, gzipping, etc.) that set it apart. It also seems to be the fastest growing Jekyll-related gem these days, which I take to mean that it is gaining traction in the community.

Louannlouanna answered 23/11, 2012 at 7:38 Comment(1)
I was enjoying using this but it looks like development has halted? Using github.com/ixti/jekyll-assets for now.Bessie
B
3

For JS and CSS you can use the Jekyll Asset Bundler It uses the yui-compressor or closure-compiler gems.

Brawl answered 4/11, 2012 at 17:26 Comment(0)
L
0

For images, I made a drop-in plugin that runs the images through image_optim:

https://gist.github.com/sffc/a828267913591159ab1cc3e1bfde20d7

Leeds answered 17/6, 2018 at 16:12 Comment(0)
O
0

This one seems fairly updated as compared to other plugins and minifies HTML/XML/CSS/JS Minifier utilising yui-compressor, and htmlcompressor
https://github.com/digitalsparky/jekyll-minifier

Outvote answered 11/11, 2019 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.