After 2 years and over 2,500 active installs in the plugin store, we’ve decided that the time is finally right to bring templating performance hints, previously provided by the Blitz Recommendations plugin, directly into Blitz. There is now no excuse for not eager-loading elements in your Twig templates, as the new utility keeps track of opportunities as pages are visited and tells you about them!
Oh, it’s been getting so hard
Livin’ with the things you do to me,
My dreams are getting so strange
I’d like to tell you everything I see.
What’s great about having this feature now available directly in Blitz, is that you can have it check for eager-loading opportunities across all pages with the click of a button. Simply use the Generate Cache
button (or console command) in the Blitz Cache
utility to generate all of your site’s pages. Once complete, go to the new Blitz Hints
utility, which will list any opportunities for eager-loading elements including the field name, the template and the line number.
The feature is also now able to distinguish between eager-loading opportunities for regular element queries and for elements auto-injected via route variables. The former should be prioritised and are always visible, whereas eager-loading elements on auto-injected elements is generally less critical and are hidden by default (and don’t count towards the badge total).
{# Regular element query. #}
{% set entries = craft.entries.section('articles').all() %}
{# Element query on an entry auto-injected via route variables. #}
{% set image = entry.image.one() %}
If you are not (yet) a user of the Blitz plugin then rest assured, you can continue using the free Blitz Recommendations plugin. Under the hood, they use the same logic, which has been extracted out into the Blitz Hints package.
This feature was added in Blitz 4.1.0 and Blitz Recommendations 2.1.0, both of which require Craft 4.