Including CSS in Jekyll
Jekyll is a blog aware static-site generator. It’s great for building simple pages like Code Guide or blogs like this one. Lately, I’ve been a big fan of Jekyll’s include functionality.
Now, most folks use _includes
for standard partials like a site’s header or footer. Lately though, I’ve been using them to easily include CSS dependencies for fewer page requests.
Say you have three CSS files to include in your Jekyll project. Normally you’d do something like this:
<link rel="stylesheet" href="site.css">
<link rel="stylesheet" href="font-awesome.css">
<link rel="stylesheet" href="syntax.css">
With Jekyll, you can turn that into one file during site generation with includes and YAML front-matter. Here’s an example Gist.
The front-matter tells Jekyll to treat this page as a buildable file rather than simply another asset to copy to the generated _site
folder. With that in place, add any _includes
you like, and run jekyll serve
.
Enjoy!