I have a directory of sea ports with a google map that loads about 450 records. The map and listings and pagination work fine. On their own, I get a 2.5 sec page load average.
However as soon as I add a search form that populates a chained select for countries and ports the load time goes up to 8 secs.
The search form code looks like this
{% set categories = craft.categories.group('locations').limit(null) %}
<label>Country</label>
<select id="countries" class="countries" name="country">
<option value="">Select...</option>
{% cache %}
{% for country in categories %}
{% if country.level == 1 %}
<option value="{{ country.slug }}">{{ country.title }}</option>
{% endif %}
{% endfor %}
{% endcache %}
</select>
<label>Ports</label>
<select id="ports" name="port" class="ports" disabled="disabled">
<option value="">Select a country first</option>
{% cache %}
{% for port in categories %}
<option value="{{ port.slug }}" class="{{ port.parent | lower }}">{{ port.title }}</option>
{% endfor %}
{% endcache %}
</select>
It seems that this code cost about 5 seconds of load time.
I have checked the profile output and seen the query for the categories. It's huge. I can't see how to get the page to load faster as I can't see eager loading applying to a category group, and caching doesn't really help here.
Any ideas on how to optimise this portion?
ports
in your initialcategories
query? craftcms.com/docs/templating/eager-loading-elements{% if country.level == 1 %}
), but I’m not seeing anything similar for the Ports menu. How are you limiting the Ports menu to the second-level categories?