Optimizing when to include


#1

I have an include file with a wad of narly html that turns into feedback form, lets call it feedback.html

I need to sometimes include this, and sometimes not. For sake of this conversation, lets just assume that the condition boils down to if foo == 'bar'

Which way is faster/better? I’m trying to optimize for build time, as my writers use serve mode a lot, and precious seconds wasted on each rebuild loop add up across the day.

Always include the file in the layout, and put the condition inside of the include:

layout.html

{% include feedback.html %}

feedback_html

{% if foo == 'bar' %}
HTML...
{% endif %}

Or put the condition in the layout, and have the include just straight flat file

layout.html

{% if foo == 'bar' %}
{% include feedback.html %}
{% endif %}

feedback.html

HMTL…


#2

I would check before including the file - your second example.

Not sure what difference it makes- do a test and let us know! I have not really read much about how these types of things change build times. There is a -profile flag you can do (I think that is what it is called) that will tell you how much time each step took which may help analyze which is better.

If you are worried about precious seconds in your build times I would look at using Gulp to process sass and other assets like images as it is much much quicker at it than jekyll is.