Eager-Loading child elements in a multi-level structure section I have a structure that looks like this:


Experiment ( Level 1)


Cages (Level 2)
Animals (Level 3)
Measurement (Level 4)



I am outputting this information into some inline JSON like so: 

{% set mice = craft.entries({
    'section' : 'experiments',
    'level' : 3,
    'descendantOf' : entry.id,
}) %}

&lt;script&gt;
  var data = [
    {% for mouse in mice %}
    {
      "Cage": "{{ mouse.parent.title }}",
      "Mouse": "{{ mouse.title }}",
      "measurements": [
        {% for data in mouse.children.order('postDate') %}
        {
          "Date": "{{ data.postDate| date("d-M") }}",
          "Weight(g)": "{{ data.weight }}",
          "Length": "{{ data.length }}",
          "Depth": "{{ data.depth }}",
          "Tumor Volume": {{ data.tumourVolume }}
        }{% if not loop.last %}, {% endif %}
        {% endfor %}
      ]
    }{% if not loop.last %}, {% endif %}
    {% endfor %}
  ];
&lt;/script&gt;


This is ok until entries start to increase, the TTFB begins to add up significantly - I am wondering if there is a way to eager load this sort of structure? The entries are very dynamic so caching isn't an option.

Thanks!
To use eager-loading for the child elements add 'children' to the with parameter.

{% set mice = craft.entries({
    section: 'experiments',
    level: 3,
    descendantOf: entry.id,
    with: ['children', {order: 'postDate asc'}],
}) %}