Inline JavaScript created by js.Build

Hey all,

I use js.Build to build my JavaScript file like that:

{{ $script := resources.Get .path | js.Build (dict "target" "es2015" "minify" true) | fingerprint }}
<script type="text/javascript" src="{{ $script.RelPermalink }}" defer></script>

I usually use defer for performance reason, but I now have a script that I’d like to execute immediately. Of course I could just remove the defer and be done with it. Instead, I’d like to inline the minified JavaScript string created by js.Build.

Is that possible with Hugo? I somehow assume it’s not but i’d like to be sure.

Just call the resources .Content

{{ $script := resources.Get .path | js.Build (dict "target" "es2015" "minify" true) | fingerprint }}
<script>
{{ $script.Content | safeJS }}
</script>
2 Likes

Thank you.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.