How To Prevent Content Displaying In A Jekyll Development Environment

Show content in production but avoid it in a local Jekyll instance

Published:
Last modified:
Tags Jekyll , Environments , Adsense , Analytics , Disqus

Overview

While developing and continuously testing a jekyll site, avoiding any javascript external request can greatly improve the loading speed of each page.

In the case of advertisements, also prevents from accidentally clicking developer’s own ads which can cause an account suspension.

The basic concept to make it possible is to create different Jekyll builds for development and production environments.

Environment

The easiest way to avoid any external javascript request is to detect the environment on which Jekyll is running in liquid templates using the environment variable JEKYLL_ENV at build (or serve) time.

To build a production ready jekyll site it can be specified like this:

$ JEKYLL_ENV=production jekyll build

If none environment is explicitly set, then it uses by default JEKYLL_ENV=development

When using a Bundler command it should be used like:

$ JEKYLL_ENV=production bundle exec jekyll build

Detecting the environment in templates

To detect the environment in Jekyll liquid templates, jekyll.environment variable contains the current environment.

For example, to avoid showing post tags in development:

{% if jekyll.environment == "production" %}
 {{ post.tags }}
{% endif %}
Uruguay
Marcelo Canina
I'm Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.
comments powered by Disqus


How to prevent code execution when developing in Jekyll but displaying it in production. Avoid ads, analytics and disqus loading while developing.

Clutter-free software concepts.
Translations English Español

Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.

Powered by SimpleIT Hugo Theme

·