Environments in Jekyll
Some code belongs on a production site but gets in the way during local development. Analytics and comment scripts are common examples. Jekyll exposes the current environment as jekyll.environment, so you can include that code conditionally.
{% if jekyll.environment == "production" %}
<script>
// JavaScript snippet...
</script>
{% endif %}
The block is rendered only when the environment is production. Set the value when you build or serve the site:
JEKYLL_ENV=production jekyll build
For local work, you can use JEKYLL_ENV=development jekyll serve --watch, although development is already Jekyll’s default. I prefer keeping production-only integrations behind this small check rather than loading them locally and adding exceptions elsewhere.