Skip to content

Commit 83cbfa1

Browse files
committed
Minify and fingerprint js
1 parent 8b7521d commit 83cbfa1

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

layouts/partials/js.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
{{ $isDev := ne hugo.Environment "production" }}
12
{{ $allJS := resources.Get "js/slate/all.js" }}
23
{{ $allNoSearchJS := resources.Get "js/slate/all_nosearch.js" }}
34
{{ $importsAll := partial "funcs/extract_js_requirements.html" (dict "resource" $allJS "visited" newScratch ) | uniq }}
45
{{ $importsAllNoSearch := partial "funcs/extract_js_requirements.html" (dict "resource" $allNoSearchJS "visited" newScratch ) | uniq }}
56
{{ $jsAll := partialCached "funcs/get_and_concat.html" (dict "imports" $importsAll "target" "js/all.js" ) "all" }}
67
{{ $jsAllNoSearch := partialCached "funcs/get_and_concat.html" (dict "imports" $importsAllNoSearch "target" "js/all_nosearch.js" ) "no search"}}
8+
{{ if not $isDev }}
9+
{{ $jsAll = $jsAll | minify | fingerprint }}
10+
{{ $jsAllNoSearch = $jsAllNoSearch | minify | fingerprint }}
11+
{{ end }}
712
{{ if .Param "search" }}
8-
<script src='{{ $jsAll.RelPermalink }}'></script>
13+
<script src='{{ $jsAll.RelPermalink }}'{{ if not $isDev }} integrity="{{ $jsAll.Data.Integrity }}"{{ end }}></script>
914
{{ else }}
10-
<script src='{{ $jsAllNoSearch.RelPermalink }}'></script>
15+
<script src='{{ $jsAllNoSearch.RelPermalink }}'{{ if not $isDev }} integrity="{{ $jsAllNoSearch.Data.Integrity }}"{{ end }}></script>
1116
{{ end }}

0 commit comments

Comments
 (0)