Skip to content

Commit

Permalink
Use defer to load styles
Browse files Browse the repository at this point in the history
A new feature coming in next Hugo.

See gohugoio/hugo#12587
  • Loading branch information
bep committed Jun 21, 2024
1 parent 4ce5197 commit 744c036
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
Empty file removed .hugo_build.lock
Empty file.
30 changes: 12 additions & 18 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ disableKinds = ["page", "section", "taxonomy", "term"]
[module]
[module.hugoVersion]
extended = false
min = "0.112.0"
min = "0.128.0"
[[module.mounts]]
source = "assets"
target = "assets"
[[module.mounts]]
source = "hugo_stats.json"
target = "assets/watching/hugo_stats.json"

[build]
writeStats = true
[[build.cachebusters]]
source = "assets/watching/hugo_stats\\.json"
target = "styles\\.css"
[[build.cachebusters]]
source = "(postcss|tailwind)\\.config\\.js"
target = "css"
[[build.cachebusters]]
source = "assets/.*\\.(js|ts|jsx|tsx)"
target = "js"
[[build.cachebusters]]
source = "assets/.*\\.(.*)$"
target = "$1"
source = "hugo_stats.json"
target = "assets/notwatching/hugo_stats.json"
disableWatch = true
[build.buildStats]
enable = true
[[build.cachebusters]]
source = "assets/notwatching/hugo_stats\\.json"
target = "styles\\.css"
[[build.cachebusters]]
source = "(postcss|tailwind)\\.config\\.js"
target = "css"
19 changes: 11 additions & 8 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>
{{ .Title }}
</title>
<meta name="description" content="{{ .Description }}" />
{{/* styles */}}
{{ $options := dict "inlineImports" true }}
{{ $styles := resources.Get "css/styles.css" }}
{{ $styles = $styles | resources.PostCSS $options }}
{{ if hugo.IsProduction }}
{{ $styles = $styles | minify | fingerprint | resources.PostProcess }}
{{ with (templates.Defer (dict "key" "styles" "data" "foo")) }}
{{ warnf "deferred: %s" . }}
{{ $options := dict "inlineImports" true }}
{{ $styles := resources.Get "css/styles.css" }}
{{ $styles = $styles | resources.PostCSS $options }}
{{ if hugo.IsProduction }}
{{ $styles = $styles | minify | fingerprint }}
{{ end }}
<link href="{{ $styles.RelPermalink }}" rel="stylesheet" />
{{ end }}
<link href="{{ $styles.RelPermalink }}" rel="stylesheet" />

</head>
<body class="my-10">
<div class="container px-4 lg:mx-auto">
Expand Down

0 comments on commit 744c036

Please sign in to comment.