Skip to content

benbalter/jekyll-include-cache

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Dec 19, 2016
Sep 16, 2021
Dec 19, 2016
Mar 21, 2019

Jekyll Include Cache

A Jekyll plugin to cache the rendering of Liquid includes

CI

What it does

If you have a computationally expensive include (such as a sidebar or navigation), Jekyll Include Cache renders the include once, and then reuses the output any time that includes is called with the same arguments, potentially speeding up your site's build significantly.

Usage

  1. Add the following to your site's Gemfile:
gem 'jekyll-include-cache'
  1. Add the following to your site's config file:
plugins:
  - jekyll-include-cache

💡 If you are using a Jekyll version less than 3.5.0, use the gems key instead of plugins.

  1. Replace {% include foo.html %} in your template with {% include_cached foo.html %}

One potential gotcha

For Jekyll Include Cache to work, you cannot rely on the page context to pass variables to your include (e.g., assign foo=bar or page.title). Instead, you must explicitly pass all variables to the include as arguments, and reference them within the include as include.foo (instead of page.foo or just foo).

Good

In your template:

{% include_cached shirt.html size=medium color=red %}

In your include:

Buy our {{ include.color }} shirt in {{ include.size }}!

Bad

In your template:

{% assign color=blue %}
{% include_cached shirt.html %}

In your include:

Buy our {{ color }} shirt in {{ page.size }}!