{{- if .content -}}
    <script type="text/javascript">
        {{- .content | safeJS -}}
    </script>
{{- else if strings.HasPrefix .source "<script" -}}
    {{- safeHTML .source -}}
{{- else -}}
    {{- $src := .source -}}
    {{- $integrity := .integrity -}}
    {{- if (urls.Parse $src).Host | not -}}
        {{- $res := resources.Get $src -}}
        {{- with .template -}}
            {{- $res = $res | resources.ExecuteAsTemplate . $.context -}}
        {{- end -}}
        {{- if .minify -}}
            {{- $res = $res | minify -}}
        {{- end -}}
        {{- with .fingerprint -}}
            {{- $res = $res | fingerprint . -}}
            {{- $integrity = $res.Data.Integrity -}}
        {{- end -}}
        {{- $src = $res.RelPermalink -}}
    {{- end -}}
    <script type="text/javascript" src="{{ $src }}"{{ if .crossorigin }} crossorigin="anonymous"{{ end }}{{ with $integrity }} integrity="{{ . }}"{{ end }}{{ if .async }} async{{ end }}{{ if .defer }} defer{{ end }}{{ with .attr }} {{ . | safeHTMLAttr }}{{ end }}></script>
{{- end -}}
