Skip to content

Commit 45fe28c

Browse files
committed
docs: use defer when possible for JS
1 parent 6922f5d commit 45fe28c

File tree

12 files changed

+20
-10
lines changed

12 files changed

+20
-10
lines changed

site/assets/js/stackblitz.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const openBootstrapSnippet = (htmlSnippet, jsSnippet, classes) => {
4141
<link href="${cssCdn}" rel="stylesheet">
4242
<link href="https://getbootstrap.com/docs/${docsVersion}/assets/css/docs.css" rel="stylesheet">
4343
<title>Bootstrap Example</title>
44-
<${'script'} src="${jsBundleCdn}"></${'script'}>
44+
<${'script'} defer src="${jsBundleCdn}"></${'script'}>
4545
</head>
4646
<body class="p-3 m-0 border-0 ${classes}">
4747
<!-- Example Code Start-->

site/content/docs/5.3/examples/cheatsheet-rtl/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- "../cheatsheet/cheatsheet.rtl.css"
66
extra_js:
77
- src: "../cheatsheet/cheatsheet.js"
8+
defer: true
89
body_class: "bg-body-tertiary"
910
direction: rtl
1011
---

site/content/docs/5.3/examples/cheatsheet/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- "cheatsheet.css"
66
extra_js:
77
- src: "cheatsheet.js"
8+
defer: true
89
body_class: "bg-body-tertiary"
910
---
1011

site/content/docs/5.3/examples/checkout-rtl/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- "../checkout/checkout.css"
77
extra_js:
88
- src: "../checkout/checkout.js"
9+
defer: true
910
body_class: "bg-body-tertiary"
1011
---
1112

site/content/docs/5.3/examples/checkout/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- "checkout.css"
66
extra_js:
77
- src: "checkout.js"
8+
defer: true
89
body_class: "bg-body-tertiary"
910
---
1011

site/content/docs/5.3/examples/dashboard-rtl/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
extra_js:
88
- src: "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.js"
99
integrity: "sha384-eI7PSr3L1XLISH8JdDII5YN/njoSsxfbrkCTnJrzXt+ENP5MOVBxD+l6sEG4zoLp"
10+
defer: true
1011
- src: "dashboard.js"
12+
defer: true
1113
---
1214

1315
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">

site/content/docs/5.3/examples/dashboard/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
extra_js:
77
- src: "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.js"
88
integrity: "sha384-eI7PSr3L1XLISH8JdDII5YN/njoSsxfbrkCTnJrzXt+ENP5MOVBxD+l6sEG4zoLp"
9+
defer: true
910
- src: "dashboard.js"
11+
defer: true
1012
---
1113

1214
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">

site/content/docs/5.3/examples/offcanvas-navbar/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- "offcanvas-navbar.css"
66
extra_js:
77
- src: "offcanvas-navbar.js"
8+
defer: true
89
body_class: "bg-body-tertiary"
910
aliases: "/docs/5.3/examples/offcanvas/"
1011
---

site/content/docs/5.3/examples/sidebars/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- "sidebars.css"
66
extra_js:
77
- src: "sidebars.js"
8+
defer: true
89
body_class: ""
910
---
1011

site/layouts/_default/docs.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ <h1 class="bd-title mb-0" id="content">{{ .Title | markdownify }}</h1>
6767
{{ end }}
6868
{{ define "footer" }}
6969
{{ range .Page.Params.extra_js -}}
70-
<script{{ with .async }} async{{ end }} src="{{ .src }}"></script>
70+
<script{{ with .async }} async{{ end }}{{ with .defer }} defer{{ end }} src="{{ .src }}"></script>
7171
{{- end -}}
7272
<div class="position-fixed" aria-hidden="true"><input type="text" tabindex="-1"></div>
7373
{{ end }}

site/layouts/_default/examples.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@
159159
{{ .Content }}
160160

161161
{{- if hugo.IsProduction -}}
162-
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.min.js" {{ printf "integrity=%q" .Site.Params.cdn.js_bundle_hash | safeHTMLAttr }}></script>
162+
<script defer src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.min.js" {{ printf "integrity=%q" .Site.Params.cdn.js_bundle_hash | safeHTMLAttr }}></script>
163163
{{- else -}}
164-
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
164+
<script defer src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
165165
{{- end }}
166166

167167
{{ range .Page.Params.extra_js -}}
168-
<script{{ with .async }} async{{ end }} src="{{ .src }}"{{ with .integrity }} {{ printf "integrity=%q" . | safeHTMLAttr }} crossorigin="anonymous"{{ end }}></script>
168+
<script{{ with .async }} async{{ end }}{{ with .defer }} defer{{ end }} src="{{ .src }}"{{ with .integrity }} {{ printf "integrity=%q" . | safeHTMLAttr }} crossorigin="anonymous"{{ end }}></script>
169169
{{- end -}}
170170
</body>
171171
</html>

site/layouts/partials/scripts.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{ if hugo.IsProduction -}}
2-
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.min.js" {{ printf "integrity=%q" .Site.Params.cdn.js_bundle_hash | safeHTMLAttr }}></script>
2+
<script defer src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.min.js" {{ printf "integrity=%q" .Site.Params.cdn.js_bundle_hash | safeHTMLAttr }}></script>
33
{{ else -}}
4-
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
4+
<script defer src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
55
{{- end }}
66

77
{{- $esbuildOptions := dict "target" "es2019" -}}
@@ -12,11 +12,11 @@
1212
{{- end }}
1313

1414
{{- $applicationJs := resources.Get "js/application.js" | js.Build $esbuildOptions | resources.Copy (path.Join $targetDocsJSPath "/assets/js/application.js") }}
15-
<script src="{{ $applicationJs.RelPermalink }}"></script>
15+
<script defer src="{{ $applicationJs.RelPermalink }}"></script>
1616

1717
{{- if (ne .Page.Layout "examples") -}}
1818
{{- $searchJs := resources.Get "js/search.js" | js.Build $esbuildOptions | resources.Copy (path.Join $targetDocsJSPath "/assets/js/search.js") }}
19-
<script async src="{{ $searchJs.RelPermalink }}"></script>
19+
<script defer src="{{ $searchJs.RelPermalink }}"></script>
2020
{{- end -}}
2121

2222
{{ if eq .Page.Layout "docs" -}}
@@ -30,5 +30,5 @@
3030
-}}
3131
{{- $esbuildOptions = merge $esbuildOptions (dict "params" $esbuildParams) -}}
3232
{{- $stackblitzJs := resources.Get "js/stackblitz.js" | js.Build $esbuildOptions | resources.Copy (path.Join $targetDocsJSPath "/assets/js/stackblitz.js") }}
33-
<script async src="{{ $stackblitzJs.RelPermalink }}"></script>
33+
<script defer src="{{ $stackblitzJs.RelPermalink }}"></script>
3434
{{- end -}}

0 commit comments

Comments
 (0)