What Are Jekyll Environments

Editor Note
To go straight to the Jekyll environments Howto, Click Here

Overview

Jekyll environments allow changing specific portions of your Jekyll site, with a single command at build time.

This is useful for testing different versions, or hiding or enabling portions of your website.

What Are Some Uses For Jekyll Environment

You could create a statics page right within your website, which shows things like word count, or testing features.

Google Analytics can track page views on your site, however, tracking page views while still actively developing can skew results. You probably only want to keep track of page views from your visitors, not from your developers and testers. Luckily, you can configure the production environment to use your Google analytics code, while having it disabled on the development environment.

More advanced developers may be using Google Tag Manager. You might already know that you can create tags for separate environments, which trigger various actions using the Google Tag Manager. Each tag will have a different code to implement into your website, and with Jekyll’s environments, you can configure Jekyll to use these different tags for different environments.

Jekyll Environments vs Multiple Jekyll Configs

The Jekyll _config.yml file has a similar function to using environments, and in some cases can be used to accomplish the same goals. They can hold multiple versions of your site, and allow you to switch easily between them. They’re both set up in your Jekyll files, and are chosen during build.

However, the config file is meant more for site-wide configuration, rather than controlling how specific pages, posts, or sections are displayed.

Take a look at a snippet from the default _config.yml file provided by the minima Jekyll theme:

title: Your awesome title
author:
  name: GitHub User
  email: your-email@domain.com
theme: minima
plugins:
  - jekyll-feed
  - jekyll-seo-tag

These site-wide configuration variables can be changed with different _config.yml files, but if you only need to change small portions of your code, you would use environments instead. Typically when a _config.yml is chosen, it won’t need to switch back and forth.

Environments on the other hand, changes content of site. It allows adding or removal of HTML, specifying different colors, or changing CSS styling, depending on environment set.

Now that you know what Jekyll Environments are, check out this post to learn how to use them.