Jekyll Relative URL Error Fix
In this tutorial, you'll learn about Jekyll Relative URL Error Fix. We cover key concepts, practical examples, and best practices.
The Problem
Broken CSS and links when deploying to a subpath like https://user.github.io/repo/.
<link rel="stylesheet" href="/css/main.css">
This resolves to https://user.github.io/css/main.css instead of https://user.github.io/repo/css/main.css.
Wrong
<link rel="stylesheet" href="/css/main.css">
Output: 404 Not Found — /css/main.css
Absolute paths break when the site is served from a subdirectory.
Right
Use relative_url filter:
<link rel="stylesheet" href="{{ '/css/main.css' | relative_url }}">
Or prepend site.baseurl:
<link rel="stylesheet" href="{{ site.baseurl }}/css/main.css">
Set baseurl in _config.yml:
baseurl: "/repo"
Output: <link rel="stylesheet" href="/repo/css/main.css">
Prevention
- Use
relative_urlfilter for all asset paths - Set
baseurlin config for subpath deployment - Test locally with
JEKYLL_ENV=production bundle exec jekyll serve
Common Mistakes with relative url
- Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
These mistakes appear frequently in real-world JEKYLL code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro