Does this template to import a bunch of style sheets from the assets look okay?

Since I am a bit new to Hugo’s Go templating, I just wanted someone to look this loop over to import CSS from the assets/css/ directory. Does this look okay or could it be done better?

{{- range slice "css/main.css" "css/syntax.css" "css/phosphor.css" -}}
  {{- with resources.Get . -}}
    {{ if hugo.IsDevelopment -}}
      <link rel="stylesheet" href="{{ .RelPermalink }}">
    {{- else -}}
      {{- with . | minify | fingerprint -}}
        <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
      {{- end -}}
    {{- end -}}
  {{- end -}}
{{- end -}}

Looks fine to me, but you might want to concatenate them into one file instead of three.

https://gohugo.io/functions/resources/concat/

Is there a benefit of doing so?

The browser only needs to download and cache one file instead of three files.

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