Programming

Trailing Slashes on URLs: Contentious or Settled? | CSS-Tips


A enjoyable deep dive from Zach. Do you may have an opinion on which it’s best to use?

1) https://web site.com/foo/
2) https://web sites.com/foo

The primary possibility has a “trailing slash.” The second doesn’t.

I’ve all the time most popular this pondering: you utilize a trailing slash if that web page has little one pages (as in, it’s one thing of a listing web page, even when has distinctive content material of its personal). If it’s the end-of-the-line (of content material), no trailing slash.

I say that, however this very website doesn’t observe it. Weblog posts on this website are like css-tricks.com/blog-post/ with a trailing slash and in case you go away off the trailing slash, WordPress will redirect to incorporate it. That’s a part of the explanation Zach is right here. Redirects include a efficiency penalty, so it’s supreme to have it occur as sometimes attainable.

Efficiency is one factor, however web optimization is one other one. When you render the identical content material, each with and and not using a trailing slash, that’s theoretically a reproduction content material penalty and a no-no. (Though that appears bizarre to me, I might assume Google would sensible sufficient to not be terribly involved by this.)

The place sources resolve to looks like the largest deal to me. Right here’s Zach:

When you’re utilizing relative useful resource URLs, the property could also be lacking on Vercel, Render, and Azure Static Net Apps (relying on which duplicated endpoint you’ve visited).

<img src="https://css-tricks.com/trailing-slashes-on-urls-contentious-or-settled/picture.avif"> on /useful resource/ resolves to /useful resource/picture.avif

<img src="https://css-tricks.com/trailing-slashes-on-urls-contentious-or-settled/picture.avif"> on /useful resource resolves to /picture.avif

That’s a non-trivial distinction and, to me, a cause the redirect is value it. Can’t be having a web page with damaged sources for one thing this foolish.

What complicates that is that the site-building framework may need opinions about this and a internet hosting supplier may need opinions about this. As Zach notes, there are some disagreements amongst hosts, so it’s one thing to observe for.

Me, I’d go together with the grain as a lot as I probably might. So long as redirects are in place and I don’t must override any config, I’m cool.


Direct Hyperlink →

Leave a Reply

Your email address will not be published.

Back to top button