How To Prevent Content Displaying In A Jekyll Development Environment
Show content in production but avoid it in a local Jekyll instance
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 %}
- Multilingual Jekyll Without PluginsMay 8, 2017
- Host a Jekyll Website With Pretty Urls In Amazon S3 and CloudfrontApril 24, 2017
- Get A List Of Categories Based In Subfolders In JekyllMarch 3, 2017
- 5 Steps To Add Bootstrap 4 To Jekyll The Right WayFebruary 27, 2017
- Automated Deployment Of Jekyll Websites To Github Pages With A Git Push To GithubNovember 8, 2016
- How To Use Bower Scss With JekyllJune 18, 2016
- How to implement breadcrumbs on a Jekyll site with nested categoriesJune 7, 2016
- How To Handle Adsense In A Jekyll Development EnvironmentJune 6, 2016
- How To Prevent Content Displaying In A Jekyll Development Environment
Articles
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
·