feat: Add fingerprints to the JS file URL to utilize HTTP caching.

This commit is contained in:
xiaoxiyao 2024-09-23 17:13:57 +08:00
parent 2a18a92901
commit 5c2c38f245

View File

@ -1,12 +1,12 @@
{{- partial "helper/external" (dict "Context" . "Namespace" "Vibrant") -}} {{- partial "helper/external" (dict "Context" . "Namespace" "Vibrant") -}}
{{- $opts := dict "minify" hugo.IsProduction -}} {{- $opts := dict "minify" hugo.IsProduction -}}
{{- $script := resources.Get "ts/main.ts" | js.Build $opts -}} {{- $script := resources.Get "ts/main.ts" | js.Build $opts | fingerprint -}}
<script type="text/javascript" src="{{ $script.RelPermalink }}" defer></script> <script type="text/javascript" src="{{ $script.RelPermalink }}" defer></script>
{{- with resources.Get "ts/custom.ts" -}} {{- with resources.Get "ts/custom.ts" -}}
{{/* Place your custom script in HUGO_SITE_FOLDER/assets/ts/custom.ts */}} {{/* Place your custom script in HUGO_SITE_FOLDER/assets/ts/custom.ts */}}
{{- $customScript := . | js.Build $opts -}} {{- $customScript := . | js.Build $opts | fingerprint -}}
<script type="text/javascript" src="{{ $customScript.RelPermalink }}" defer></script> <script type="text/javascript" src="{{ $customScript.RelPermalink }}" defer></script>
{{- end -}} {{- end -}}