3 ms·
I actually like that it does this. In your example where you’d want it to infer relative URLs, what happens when that code is executed in Node? > If you're bro
by afavour 2y ago
I actually like that it does this. In your example where you’d want it to infer relative URLs, what happens when that code is executed in Node?
> If you're browsing a folder, the whole document.location is the baseURL, but if you are browsing a file (ie ends in .php or .html) it isn't
I’m not sure I understand what you’re saying here. The second argument in the URL constructor works as a “relative to” argument. If your URL starts with / it doesn’t matter if there’s a file or not, it’ll start from the domain root.
- Izkata 2y agoThere's either 4 or 6 combinations (depending on whether you consider the domain-only case separate from path or not): www.example.com + /images/foo.jpg -> www.example.com/images/foo.jpg www.example.com/static/ + /images/foo.jpg -> www.example.com/images/foo.jpg www.example.com/static/index.html + /images/foo.jpg -> www.example.com/images/foo.jpg www.example.com + images/foo.jpg -> www.example.com/images/foo.jpg www.example.com/static/ + images/foo.jpg -> www.example.com/static/images/foo.jpg www.example.com/static/index.html + images/foo.jpg -> www.example.com/static/index.htmlimages/foo.jpg (naive and wrong) -> www.example.com/static/images/foo.jpg (extra work) They were referring to the difference between the 5th and 6th (probably didn't notice it was an absolute path), you're referring to the first 3 together vs the others.
- afavour 2y agoInteresting, I’ve never run into that. In the last example I’d just do www.example.com/static/index.html + ./images/foo.jpg