Update Batch.md

This commit is contained in:
Bjørn Erik Pedersen 2025-01-06 10:03:04 +01:00 committed by GitHub
parent eb841ce66a
commit 15a8b1de61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -256,6 +256,12 @@ Eeach [`Resource`] will be of media type `application/javascript` or `text/css`.
In a template you would typically handle one group with a given `ID` (e.g. scripts for the current section). Because of the concurrent build, this needs to be done in a [`templates.Defer`] block:
{{% note %}}
The [`templates.Defer`] acts as a synchronisation point to handle scripts added concurrently by different templates. If you have a setup with where the batch is created in one go (in one template), you don't need it.
See [this discussion] for more.
{{% /note %}}
```go-html-template
{{ $group := .group }}
{{ with (templates.Defer (dict "key" $group "data" $group )) }}
@ -320,4 +326,4 @@ console.log('entrypoints-workaround.js');
[script options]: #script-options
[script]: #script
[SetOptions]: #optionssetter
[with]: https://gohugo.io/functions/go-template/with/
[with]: https://gohugo.io/functions/go-template/with/