Speed up jekyll site generation with rsync
Posted on July 26, 2014 • 2 minutes • 214 words
Jekyll doesn’t support incremental generation so if your site contains loads of static assets like image, audios,.. jekyll is gonna stroke everytime you re-generate your site by deleting and re-generate/re-coppying everything. This little trick below will help you speeding up jekyll generation process by skipping all the static assets that you specified, until jekyll comes up with a better solution.
-
Rename your static asset folder with underscore in front. jekyll is going to ignore this when generating site. Assume this folder is named
images
. You will rename it to be_images
. -
In your
_config.yml
, add the line below. This line basically means that when re-generating, the folder calledimages
in generated folder is not getting touched.
keep_files: ["images"]
- Keeping in the source and generated folder in sync with a little plugin and rsync. Created a file name
rsync_image_generator.rb
in_plugins
folder with the content below.
module Jekyll
class RsyncImageGenerator < Generator
def generate(site)
system('mkdir -p _site');
system('rsync --archive --delete _img/ _site/img/');
end
end
end
From now on, jekyll will ignore the _images
folder in your source and images
in _sites
folder when generating your site. We keep it in sync by using rsync, which is much better/faster than delete/copy process jekyll is using.
Github Pages does support jekyll gems now but it’s kinda limited.