4 ms·
Very much required if you want to use relative URL calculations. Stumbled across this in Go yesterday Compare a relativeUrl ref from 'http://localhost/1.0 htt
by neilwilson 5y ago
Very much required if you want to use relative URL calculations.
Stumbled across this in Go yesterday
Compare a relativeUrl ref from 'http://localhost/1.0 http://localhost/1.0' vs. 'http://localhost/1.0/ http://localhost/1.0/'
e.g. https://play.golang.com/p/AsUSx6bRWn6 https://play.golang.com/p/AsUSx6bRWn6
- tmpfs 5y agoThis is the correct answer. Relative paths are incorrect without a trailing slash. Use trailing slashes please.
- 3np 5y agoEither could be desired behavior and neither is incorrect. If anything, just be consistent within a single site. IMO you're most likely good as long as you consciously pick one, you know why you picked it, and stick with it.
- Enderboi 5y agoI literally just closed a ticket about this issue yesterday.. 'why are these relative URLs downloading from the parent folder'. "Because your CMS is rewriting out trailing slashes. Make it stop that, and then you'll be in the relative path you think your in". The internet uncertainty principle: It's not DNS, it's trailing slashes. (apologies to Herr Heisenberg :)
- hypertele-Xii 5y agoMaybe stop "thinking you're in a path" and actually explicitly define which path you wanna be on [1]. The <base> element has existed expressly for this purpose since 1991, although it was called <address> in the first draft. [1] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ba...
- jeroenhd 5y agoIt depends on your expectations. For example, you could construct a page on https://blog.example.com/my-summer-vacation-2020 https://blog.example.com/my-summer-vacation-2020 and load all resources in the form of static/style.css, static/comments.js, media/header.webp and so on. As long are you're aware of the differences and the way your web server resolves static content, you can pick either, whatever you prefer. I have no idea what Vercel, Render, and Azure Static Web Apps even are, but you should obviously be aware of their limitations when using them to host HTML. I'm sure there are plenty of other behaviours that differ between them and there's hardly any universal truth to be found in the decisions some big corporations once made. This article seems more about the default slug-to-content resolution algorithm from a bunch of cloud providers than it is about trailing slashes.
- xvector 5y agoWhy does .Parse trim the 1.0 when there isn't a trailing slash?
- dotancohen 5y agoBecause the term "relative" is relative to the current directory, not the current file. It's subtle, but if a directory is being referenced in a form that looks like a file (without the trailing slash) with no additional context, then the parent directory is considered.
- dotancohen 5y agoIs that per standard, or the result of an implementation detail in Go that might be different in e.g. Python?
- hn_throwaway_99 5y agoIt's a client-side thing, not a server-side thing. That is, if you have a resource (like an href to another page) in your html, and that link is a relative link, the full URL that your browser ends up requesting depends on whether there is a trailing slash or not, because "relative" is relative to the current URL's directory, and what is considered the current directory differs depending on the presence of a trailing slash.
- shellac 5y agoPart of the URI standard: return a string consisting of the reference's path component appended to all but the last segment of the base URI's path (i.e., excluding any characters after the right-most "/" in the base URI path, or excluding the entire base URI path if it does not contain any "/" characters https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.3 https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.3
- jeroenhd 5y agoI don't get it; that's just how URLs work? This is hardly unexpected behaviour in my opinion. They're not always required, it's a matter of expectation and understanding of how relative URLs work. You can see /1.0 as a file and /1.0/ as a directory, so the relative URLs make perfect sense either way.