Trailing slashes on URLs | Zach Leat

I saw Zach's poll on Twitter when they posted it, so I was intrigued to see what the results were. Most people agree with me, that URLs shouldn't have trailing slashes. It turns out that we're probably wrong, technically, but dammit it just looks better. A trailing slash implies additional content! I'm not even sure that I agree with Chris' take, though at least that distinction follows logic I can understand.

The important part, though, is what happened when Zach tested the different approaches:

Here’s what happens when a web browser makes a request to a URL representing this content:

/resource

✅ GitHub Pages, Netlify, and Cloudflare Pages redirect to the trailing slash /resource/ as expected.

🟡 Warning: Vercel, Render, and Azure Static Web Apps: slashless /resource returns content but without redirects, resulting in multiple endpoints for the same content.

/resource/

✅ All hosts agree that /resource/ should return content from resource/index.html

💔 Warning: If you’re using relative resource URLs, the assets may be missing on Vercel, Render, and Azure Static Web Apps (depending on which duplicated endpoint you’ve visited).

<img src="image.avif"> on /resource/ resolves to /resource/image.avif

<img src="image.avif"> on /resource resolves to /image.avif

In other words, the greatest level of consistency for URLs, redirects, and relative paths is always a trailing slash. The impact (particularly for SEO) varies based on host, but it's always better to just accept that (for now) aesthetics have lost.

I also fully agree with this sentiment:

Ideally, (speaking as the maintainer of Eleventy) folks working on developer tooling should craft tools to create output that uses existing conventions and can be portable to as many hosts in as many different hosting environments as possible.

Explore Other Notes

Older

Not today though

I've been enjoying They Can Talk for a while. It's a simple concept, executed extremely well: what would animals say if they could talk? Worth a …

  • <!DOCTYPE html> <html> <head> <title></title> </head> <body> <p>I saw Zach's poll on Twitter when they posted it, so I was intrigued to see what the results were. Most people agree with me, that URLs shouldn't have trailing slashes. It turns out that we're …</p> </body> </html>
  • Murray Adcock.
Journal permalink