How is everyone handling slugs in urls? and the lo...
# orm-help
t
How is everyone handling slugs in urls? and the logic for when that slug changes? Are you making slugs unique in your model? Consider this scenario: • You create a task, and it has a title. You slugify that and make it unique. So when a user visits /task/{slug} - you can fetch that unique task and get that data. • But when a user changes the title - Do you update the slug? • What happens if that url with the old slug has been linked externally (e.g. on slack, on the web etc) - how do you handle fallbacks? is there best practices to make human friendly urls like this easier to handle?
m
Hello, Either the url doesn't change, and the slug in the url doesn't reflect the title after a change. That's what happen when sometime online newspapers update their titles / articles. It happens a lot because they change the titles to test what drives more traffic to their site. You can also apply a 301 redirection (content moved permanently) if you want to change the slug in the url. There is no ONE best practice, it depends on what you want and need. šŸ™‚
āœ… 1
t
Hmm that's a fair point. We are also considering using a system where we have a more unique ID in the URL too. Such as /uv-450/{slug} Here the slug is just visual, but the real ID is in the number.
m
Yep, that' also a solution. šŸ‘ Keep in mind that this solution produces urls that are harder to remember (if you care about this aspect). It's a solution used by Youtube (and others, of course). YT use 8 characters in the url (or is it 11 characters ? šŸ¤”). Nanoid is a good lib if you want to create short ids (without going full uuid), and has a lot of options.
t
Yea we do prefer a more readable and easy to reference URL. That's why we are leaning towards a UV-XXX so there is a sequential number that's incremented for each workspace
šŸ‘ 1
m
(I would just add that it is usually a bad idea to have "sequential urls" because such an url can easily be guessed. Scenario : • I have an account and can access workspace UV-123. • Oh, there a bug in the access / auth feature 🪲 • Let's try to access another workspace by changing the url to UV-122 • Bingo, i guessed a working url that is not mine, and I can access data of other users. You can't "guess" a uuid, and brute force / random trying would take a long time.)
t
Yea it won't be a global sequential ID. The ID is going to be scoped to the workspace. The workspace slug will also be in the url.
šŸ‘ 1