You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hugo主题部署至GitHub后加载失败,如何修复完整性校验问题?

Fixing Hugo Resource Integrity Mismatch on GitHub Pages (Windows Environment)

The integrity error you're encountering stems from a line ending mismatch: Hugo generates the SHA-256 hash locally using Windows' CRLF line endings, but GitHub Pages serves files with LF line endings (Git often converts CRLF to LF during deployment). This causes the computed hash to fail validation. Here's how to fix this properly without disabling integrity checks:

1. Enforce Consistent Line Endings Across Repositories

Add a .gitattributes file to both your content repository (blog) and your GitHub Pages hosting repository (matthewcrews.github.io). This tells Git to standardize all text files to LF line endings, regardless of your local OS:

* text=auto eol=lf

With this file in place, Git will convert CRLF to LF when you commit files from Windows, ensuring the deployed files use the same line endings Hugo used to generate the integrity hash.

2. Clean and Rebuild Your Site

After setting up .gitattributes, regenerate your static files with the correct line endings:

  • Run hugo clean to delete old build artifacts
  • Rebuild your site with hugo
  • Commit the new static files to your content repository, then push to trigger GitHub Pages deployment (or manually sync to your hosting repo)

This will generate new integrity hashes aligned with LF line endings, matching what will be served on GitHub Pages.

3. Optional: Explicitly Configure Hugo Resource Handling

If the above steps don't resolve the issue, add explicit resource processing settings to your config.toml to ensure consistent hash generation:

[module]
  [[module.mounts]]
    source = "assets"
    target = "assets"
  [[module.mounts]]
    source = "static"
    target = "static"

[resources]
  [resources.css]
    minify = true
    integrity = true

This config clarifies how Hugo should handle asset files, ensuring minification and integrity hash generation use consistent formatting.

Once you complete these steps, the browser will validate the integrity hash correctly, and your theme's CSS will load without being blocked.

内容的提问来源于stack exchange,提问作者Matthew Crews

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:33:35