lameco / craft-blitz
Laméco defaults for Blitz: forced cache settings and per-site query string exclusions
Package info
github.com/Lameco-Development/craft-blitz
Type:craft-plugin
pkg:composer/lameco/craft-blitz
Requires
- php: ^8.2
- craftcms/cms: ^5.0
- putyourlightson/craft-blitz: ^5.0
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 6.2.0
- 6.1.0
- 6.0.1
- 6.0.0
- 5.0.2
- 5.0.1
- 5.0.0
- 4.0.0
- 1.1.3
- 1.1.2
- 1.0.2
- 1.0.1
- 1.0.0
- 0.2.2
- 0.2.0
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-development
- dev-feature/navigation-cache-tags
- dev-feature/database-settings
- dev-docs/upgrade-cache-reset
- dev-release/5.x
- dev-feature/blitz-docs-defaults
- dev-feature/force-ssi
- dev-release/1.x
- dev-fix/numeric-section-id
- dev-docs/local-generator-only
- dev-fix/translation-refresh-on-failed-sync
- dev-feature/translation-cache-tags
- dev-docs/translation-refresh-wording
- dev-fix/refresh-on-translation-sync
- dev-feature/craft5-release-please
- dev-fix/cache-cached-includes
- dev-fix/query-param-presence
This package is auto-updated.
Last update: 2026-11-30 14:21:06 UTC
README
Laméco defaults for Blitz: it forces one set of Blitz settings on every site and lets each site name the query string parameters that must bypass the cache.
Requirements
- PHP 8.2 or higher
- Craft CMS 5
- Blitz 5, installed and enabled
Installation
composer require lameco/craft-blitz:^6.0 php craft plugin/install _craft-blitz
The constraint matters: Packagist also carries the tags 4.0.0, 5.0.0 and 5.0.1 from an older implementation (2024).
What it forces
The plugin overrides these Blitz settings at runtime, whatever the Blitz CP settings or config/blitz.php say:
| Blitz setting | Value |
|---|---|
| Caching enabled | BLITZ_ENABLED (default off) |
| Debug | BLITZ_DEBUG (default off) |
| Included URI patterns | every URI, every site |
| Generator | LocalGenerator when BLITZ_GENERATOR=LOCAL, otherwise HttpGenerator, with concurrency 1 |
| Storage | compressed cached values |
| Refresh mode | expire the cache |
| Query string caching | cache URLs with query strings as the same page |
| Included / excluded query string params | none |
BLITZ_GENERATOR=LOCAL is for local development only, where Blitz's HTTP generator can't reach Valet's .test domains. Servers use HTTP: the local generator can't rebuild craft.blitz.includeCached() fragments, so an expired header or footer stays up.
Only pages that resolve to an entry are cached, plus the fragments of craft.blitz.includeCached().
Translations
With Enupal Translate installed, a changed site translation expires only the cached pages and craft.blitz.includeCached() fragments that show it, as Blitz recommends for content it can't track itself (craft-blitz#649):
- While Blitz caches a page or fragment, the plugin tags it with every site translation (
|t,Craft::t('site', …)) it renders. - Enupal writes each save, import or provider translation to the translation file and queues its "Syncing translations with DB" job. Just before that job runs, the plugin compares Enupal's database copy with the files, and afterwards expires the pages tagged with a changed message. A change in
translations/nl/also covers the regions that fall back to it, such asnl-NL. - If Enupal's database copy is behind the files, for example when translations were changed in git, the next sync treats those messages as changed too.
This needs a queue runner, and only happens while Blitz caching is enabled (BLITZ_ENABLED). As with any expired page, the first visit still gets the old text and queues the regeneration; the visits after that get the new text. A site that configures its own message source for the site category isn't tagged; there, a sync expires the whole cache. Edits to plugin translations through Enupal are not tracked.
Pages cached before 6.1.0 carry no translation tags, so clear the Blitz cache once after updating.
Navigation menus
With Navigation 4.1 or later installed, a menu change expires the cached pages and craft.blitz.includeCached() fragments that show that menu, at any level. When Navigation 4.1 serves a menu from its own cache, it doesn't query the menu's nodes, so Blitz can't link that menu to the pages that render it and keeps showing the old one.
- While Blitz caches a page or fragment, the plugin tags it with every menu it reads from Navigation's cache, next to its translation tags.
- When Navigation clears a menu from its cache, the plugin expires the pages tagged with that menu. For a menu whose nodes don't propagate across sites, that's only the site it changed on. For any other menu (Navigation's default propagates to all sites), it's every site, since deleting or moving a node or publishing the menu builder changes the menu on all of them while Navigation only names one. A change to all menus expires every page that shows one.
- Pages that work out the active node (
craft.navigation.getActiveNode()) are tagged as well when the menu query behind it is one Navigation caches (a menu given by handle or id, without options such aswithMenuthat bypass its cache): a menu change then also expires those pages. - Dynamic nodes are left to Blitz: Navigation queries their entries, categories or assets directly, which Blitz tracks itself.
The expiry only happens while Blitz caching is enabled (BLITZ_ENABLED) and Blitz's refreshCacheEnabled setting is on (its default; it lives in config/blitz.php). As with translations, the first visit to an expired page still gets the old menu. No template or module code is needed.
When the plugin can't tag menus, it says so in Craft's log under lameco\blitz\Plugin::_tagNavigationMenus and leaves Navigation alone:
- If Navigation is missing, disabled or older than 4.1, there's nothing to tag and it logs at info level: "Navigation is not installed or disabled, so menus are not tagged in the Blitz cache." or "Navigation menus are not tagged in the Blitz cache: Navigation 4.1 or later is not installed." Craft's default log target drops info messages outside dev mode.
- If Navigation is 4.1 or later but a Navigation update removed or changed the cache service the plugin hooks into, or the service has already been replaced or configured elsewhere (by the project or another plugin), it logs at warning level: "Navigation menus are not tagged in the Blitz cache:" followed by the reason.
While the integration is off, Blitz's own tracking and clearing the cache still work as before. Only menu changes Blitz can't see itself, those served from Navigation's cache, can then stay stale until the plugin is updated.
Pages cached before this release carry no menu tags, so clear the Blitz cache once after updating.
Query string exclusions
Because every URL with a query string is cached as the same page, a parameter that changes the output has to be listed, or its render ends up in the cache under the plain URL for every visitor. A listed parameter makes the request bypass the cache whenever it is present, whatever its value (?q=0, ?q= and ?q included). Blitz neither serves such a request from the cache nor stores it.
- Global query string params: a comma-separated list that applies to every page, for example
q,page. - Per section and entry type: rows of a section/entry type and its comma-separated parameters.
Write array parameters with or without brackets: filters[] matches ?filters[]=1 and ?filters[0]=1. Both settings can also be set in config/_craft-blitz.php, which then overrides the CP.
Which parameters to list:
-
Everything a template reads from the URL, including a Sprig component's first render: Sprig turns query string parameters into component variables, so a search or filter component that reads
query,categoryorpageneeds them listed. -
Query string pagination (
pageTrigger('?page')inconfig/general.php): listpage, since every page of a listing shares one URI:?page=2would otherwise get the cached first page, or store page two under the plain URL. -
Path pagination (
/news/p2, Craft's default) gives each page its own URI and needs nothing listed. Craft does clamp a page number past the end to the last page and answers 200, so/news/p99999gets cached as its own page, and so does every other number a crawler tries. Return a 404 instead, right after the{% paginate … as pageInfo, entries %}tag (use the template's own name forpageInfo):{% if craft.app.request.pageNum > pageInfo.totalPages %}{% exit 404 %}{% endif %}Blitz doesn't cache a 404, and drops a cached page whose URL now returns one when it regenerates it.
Clearing the cache
Where this README says to clear the Blitz cache, run both commands on every environment, in this order:
php craft blitz/cache/flush && php craft blitz/cache/clear
cleardeletes the cached pages but not their records. A deploy that runsphp craft clear-caches/all, as Deployer's stock Craft recipe does, does the same to Blitz. The records stay, and Blitz'srefresh-expiredand generate jobs keep requesting the URIs in them, including pages the current rules no longer cache.flushdeletes the records but not the cached pages. A page left without a record is still served, and an edit never expires it.- Flush first: a page cached between the two commands then ends up as a record without a file, which the next visit to that page repairs.
Blitz's own blitz/cache/refresh doesn't do this: under the forced refresh mode it only marks pages expired.
Upgrading
-
From an earlier 6.x release: on sites with Navigation 4.1 or later, clear the Blitz cache once after updating, so that pages and fragments cached before this release get the menu tags. A project that tags its menus itself (an
EVENT_INVALIDATEhandler plus tags in the templates) can drop that code. -
From 1.x: require
^6.0, runphp craft up, then clear the Blitz cache, since pages cached under the old rules stay in the cache otherwise. Then follow From an earlier 6.x release above.The forced generator and storage settings now take effect; before 6.0.0 Blitz had already built those components when the plugin set them. Cached pages also get a gzipped copy, which Craft serves to browsers that accept it, and
BLITZ_GENERATORnow picks the generator. Check that no server's.envsaysBLITZ_GENERATOR=LOCALbefore deploying. -
From 5.0.x: all of the above. The migration converts the 5.0.x rows, which stored a section ID, into one row per entry type of that section, and logs a warning for rows whose section no longer exists. Run the migration in the environment where project config is edited and commit the YAML; other environments pick it up when project config is applied.
A listed parameter now means something else. In 5.0.x it cached each value as its own page, so every
?query=…and every filter combination got its own cache entry. Now a request carrying it skips the cache: search results and filtered views are always rendered by Craft, and only the plain URL is cached.The migration can't be reverted. Going back to 5.0.x means restoring the database backup
php craft uptakes before migrating (backupOnUpdate, on by default; check that it exists before upgrading) and reverting the commit with the converted project config, together with the previous release. Craft won't apply project config whose schema version doesn't match the installed plugin.