Skip to content

Commit

Permalink
docs: use defer when possible for JS
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Mar 18, 2024
1 parent fb42018 commit 5041ec5
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion site/assets/js/stackblitz.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const openBootstrapSnippet = (htmlSnippet, jsSnippet, classes) => {
<link href="${cssCdn}" rel="stylesheet">
<link href="https://getbootstrap.com/docs/${docsVersion}/assets/css/docs.css" rel="stylesheet">
<title>Bootstrap Example</title>
<${'script'} src="${jsBundleCdn}"></${'script'}>
<${'script'} defer src="${jsBundleCdn}"></${'script'}>
</head>
<body class="p-3 m-0 border-0 ${classes}">
Expand Down
1 change: 1 addition & 0 deletions site/content/docs/5.3/examples/cheatsheet-rtl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- "../cheatsheet/cheatsheet.rtl.css"
extra_js:
- src: "../cheatsheet/cheatsheet.js"
defer: true
body_class: "bg-body-tertiary"
direction: rtl
---
Expand Down
1 change: 1 addition & 0 deletions site/content/docs/5.3/examples/cheatsheet/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- "cheatsheet.css"
extra_js:
- src: "cheatsheet.js"
defer: true
body_class: "bg-body-tertiary"
---

Expand Down
1 change: 1 addition & 0 deletions site/content/docs/5.3/examples/checkout-rtl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- "../checkout/checkout.css"
extra_js:
- src: "../checkout/checkout.js"
defer: true
body_class: "bg-body-tertiary"
---

Expand Down
1 change: 1 addition & 0 deletions site/content/docs/5.3/examples/checkout/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- "checkout.css"
extra_js:
- src: "checkout.js"
defer: true
body_class: "bg-body-tertiary"
---

Expand Down
2 changes: 2 additions & 0 deletions site/content/docs/5.3/examples/dashboard-rtl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
extra_js:
- src: "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.js"
integrity: "sha384-eI7PSr3L1XLISH8JdDII5YN/njoSsxfbrkCTnJrzXt+ENP5MOVBxD+l6sEG4zoLp"
defer: true
- src: "dashboard.js"
defer: true
---

<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
Expand Down
2 changes: 2 additions & 0 deletions site/content/docs/5.3/examples/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
extra_js:
- src: "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.js"
integrity: "sha384-eI7PSr3L1XLISH8JdDII5YN/njoSsxfbrkCTnJrzXt+ENP5MOVBxD+l6sEG4zoLp"
defer: true
- src: "dashboard.js"
defer: true
---

<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
Expand Down
1 change: 1 addition & 0 deletions site/content/docs/5.3/examples/offcanvas-navbar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- "offcanvas-navbar.css"
extra_js:
- src: "offcanvas-navbar.js"
defer: true
body_class: "bg-body-tertiary"
aliases: "/docs/5.3/examples/offcanvas/"
---
Expand Down
1 change: 1 addition & 0 deletions site/content/docs/5.3/examples/sidebars/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- "sidebars.css"
extra_js:
- src: "sidebars.js"
defer: true
body_class: ""
---

Expand Down
2 changes: 1 addition & 1 deletion site/layouts/_default/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h1 class="bd-title mb-0" id="content">{{ .Title | markdownify }}</h1>
{{ end }}
{{ define "footer" }}
{{ range .Page.Params.extra_js -}}
<script{{ with .async }} async{{ end }} src="{{ .src }}"></script>
<script{{ with .async }} async{{ end }}{{ with .defer }} defer{{ end }} src="{{ .src }}"></script>
{{- end -}}
<div class="position-fixed" aria-hidden="true"><input type="text" tabindex="-1"></div>
{{ end }}
6 changes: 3 additions & 3 deletions site/layouts/_default/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@
{{ .Content }}

{{- if hugo.IsProduction -}}
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.min.js" {{ printf "integrity=%q" .Site.Params.cdn.js_bundle_hash | safeHTMLAttr }}></script>
<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>
{{- else -}}
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
<script defer src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
{{- end }}

{{ range .Page.Params.extra_js -}}
<script{{ with .async }} async{{ end }} src="{{ .src }}"{{ with .integrity }} {{ printf "integrity=%q" . | safeHTMLAttr }} crossorigin="anonymous"{{ end }}></script>
<script{{ with .async }} async{{ end }}{{ with .defer }} defer{{ end }} src="{{ .src }}"{{ with .integrity }} {{ printf "integrity=%q" . | safeHTMLAttr }} crossorigin="anonymous"{{ end }}></script>
{{- end -}}
</body>
</html>
10 changes: 5 additions & 5 deletions site/layouts/partials/scripts.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ if hugo.IsProduction -}}
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.min.js" {{ printf "integrity=%q" .Site.Params.cdn.js_bundle_hash | safeHTMLAttr }}></script>
<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>
{{ else -}}
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
<script defer src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
{{- end }}

{{- $esbuildOptions := dict "target" "es2019" -}}
Expand All @@ -12,11 +12,11 @@
{{- end }}

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

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

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

0 comments on commit 5041ec5

Please sign in to comment.