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
mkspcd
06/04/2021, 2:11 PM
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
Tharshan
06/04/2021, 5:14 PM
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
mkspcd
06/04/2021, 5:51 PM
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
Tharshan
06/04/2021, 5:56 PM
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
mkspcd
06/05/2021, 11:01 AM
(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
Tharshan
06/05/2021, 11:29 AM
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.