5 ms·
A wisened old web developer named Rik told me that in a wiki he wrote long ago he performed his own cache-busting form of content negotiation by having urls end
by LeonB 3y ago
A wisened old web developer named Rik told me that in a wiki he wrote long ago he performed his own cache-busting form of content negotiation by having urls ends with a file type —
E.g.
/fred.html - returns html
/fred.md - returns markdown
/fred.json - returns json
(I’m guessing that also —
/fred - defaults to html
)
Though he was a strict fundamentalist restafarian in other ways he held that this had the benefits of
1. Working
2. Being readily understood
I’ve seen worse ideas. Only downside is that the urls look a bit ugly.
- euroderf 3y agoBut doesn't << /fred.md >> beat the heck out of something like << /fred?format=md >>?
- incrudible 3y agoFrom a URL aesthetics perspective, yes. Otherwise it just adds yet another dimension of how to pass a parameter.
- capableweb 3y agoDepends. Including it in the location part of the URL could make it harder to understand if you have multiple parameters, instead of just one. Using query parameters makes it very explicit, which can be good or bad depending on your use case, while sticking it into the URL makes it implicit. Together with that, you can also go for putting it in the `hash` part of the URL, if you want to keep it a secret from the server, as the server doesn't receive those parts, `/fred/#format=md`. In this case, it doesn't make much sense, but useful to know for other things, like keys and whatnot.
- matt-attack 3y agoIs don’t think I that hash method would work since that part of the URL isn’t sent to the server. It’s strictly used by the client to decide which part of the response we to show. Server has no need for it.
- giancarlostoro 3y agoI think if this is the URL behind any sort of "api" prefix in the URL (subdomain, or subdirectory) I don't see why not? It's always worked out pretty darned fantastic.
- djbusby 3y agoWho cares if urls are ugly?
- dasmith91 3y agoFront-End Developers
- quectophoton 3y agoAlso that's why single page applications are no longer technically single page. https://example.com/#!/ https://example.com/#!/about/ https://example.com/#!/users/ Are all the same page as far as the browser concerns, and if you move from `/#!/` to `/#!/users/`, and reload the page, you still load the same page (i.e. `/`). But that was too ugly for URLs, so modern websites now use browser history APIs just so they can remove 3 characters from the URL and do stuff like: https://example.com/ https://example.com/about/ https://example.com/users/ Sure, if you load `/` and move to `/about/` you don't load a new page because of browser history APIs; but if you then refresh, now you load a different, uncached page (`/about/`, instead of `/`) even if the HTML in the response is exactly the same as in `/`. Sure, the difference is not much, but to me it still seems like a waste when the response could have been cached already like in the first example.
- alex_smart 3y ago> But that was too ugly for URLs, so modern websites now use browser history APIs just so they can remove 3 characters from the URL and do stuff like Would back/forward buttons continue to work if we decided not use browser history APIs?
- quectophoton 3y agoYes, and a quick test with Mithril.js confirms it. I could try with something like React, but that's too much for a quick test.
- 3y ago
- MenhirMike 3y ago> Only downside is that the urls look a bit ugly. If /fred returns HTML, then the URL is perfectly fine, since the only real consumer of fred.md or fred.json are automated systems/API clients, and they couldn't care less what the URL looks like, only that it's predictable.
- manwe150 3y agoIt is a good trick with GitHub though that you can add .patch or .diff to the url to fetch the content without styling
- amake 3y agoIt's not just styling. The content is actually a `git format-patch` patch for the former a unified-format diff for the latter.
- going_north 3y agoAnother good one for GitHub is that you can do github.com/[username].png to get that username's profile picture.
- theblazehen 3y agoAnd github.com/[username].keys to get their ssh keys
- the_gipsy 3y agoThe URLs are different, suffix instead of the typical prefix, that's not really content negotiation.
- trevor-e 3y agoReddit does this too. You can add a ".json" suffix to any post and get the JSON response.
- navanchauhan 3y agoalso ".rss" to get a RSS feed
- kagevf 3y agoI use that with a custom feed; works well.
- paulddraper 3y agoShopify does that. Well, at least the appending .json to everything.
- arrowsmith 3y agoShopify is written in Rails, no? That's how Rails does it.
- kevincox 3y agoIt also works quite well with the browser save feature. Curl and wget will also save to a nice name by default. It may be nice if content-type tracking was universal but unfortunately file-extensions are probably the most robust way of tagging some data with a type (other than magic bytes). You can save that JSON, email it, archive it, upload it to a fileserver, someone downloads it again, decompresses it and uploads it in an HTTP form and the result will probably still be identified as JSON and highlighted by default in your editor.
- divbzero 3y agoYou can also easily serve *.html, *.json, and *.md as static files.