hugo --templateMetrics --templateMetricsHints reports a cache count of 0 with Tailwind CSS template.Defer and partialCached. Is this expected?
The “key” to understanding this is the key option passed to the templates.Defer function:
The key to use for the deferred template. This will, combined with a hash of the template content, be used as a cache key. If this is not set, Hugo will execute the deferred template on every render. This is not what you want for shared resources like CSS and JavaScript.
By way of example…
site configuration
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
project structure
content/
├── p1.md
├── p2.md
└── p3.md
layouts/
├── _partials/
│ ├── defer-no-cache-no.html
│ ├── defer-no-cache-yes.html
│ ├── defer-yes-cache-no.html
│ └── defer-yes-cache-yes.html
└── page.html
layouts/page.html
{{ partial "defer-no-cache-no.html" . }}
{{ partialCached "defer-no-cache-yes.html" . }}
{{ with (templates.Defer (dict "key" "global")) }} <-- the key is static
{{ partial "defer-yes-cache-no.html" . }}
{{ partialCached "defer-yes-cache-yes.html" . }}
{{ end }}
hugo --templateMetrics --templateMetricsHints
cache percent cached total
potential cached count count template
--------- ------- ------ ----- --------
0 0 0 3 page.html
0 0 0 1 __hdeferred/6d7359a18dad0569
100 0 0 3 _partials/defer-no-cache-no.html
100 67 2 3 _partials/defer-no-cache-yes.html
100 0 0 1 _partials/defer-yes-cache-no.html
100 0 0 1 _partials/defer-yes-cache-yes.html
Note that the two deferred templates (the last two on the list) are run only once.
If we omit the key to the templates.Defer function:
hugo --templateMetrics --templateMetricsHints
cache percent cached total
potential cached count count template
--------- ------- ------ ----- --------
0 0 0 3 __hdeferred/6d7359a18dad0569
0 0 0 3 page.html
100 0 0 3 _partials/defer-no-cache-no.html
100 67 2 3 _partials/defer-yes-cache-yes.html
100 0 0 3 _partials/defer-yes-cache-no.html
100 67 2 3 _partials/defer-no-cache-yes.html
Test site:
git clone --single-branch -b hugo-forum-topic-56069 https://github.com/jmooring/hugo-testing hugo-forum-topic-56069
cd hugo-forum-topic-56069
hugo --templateMetrics --templateMetricsHints
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.