Is it a bad idea to encode UUIDs for shorter URLs?

0
11
Asked By CuriousCoder42 On

I'm trying to shorten the public URLs I use for my posts. Right now, I'm using UUIDs as primary keys, which result in long URLs like `/posts/550e8400-e29b-41d4-a716-446655440000`. I'm considering encoding the UUIDs in responses using Base64URL and decoding them in requests with middleware to achieve shorter URLs. Does anyone think this is an anti-pattern, or do you have better solutions?

5 Answers

Answered By UserFriendly47 On

No need to stress about public IDs; they shouldn't be typed in manually anyway. If you want shorter URLs, consider using something like Sqid for auto-increment IDs or converting to base 58 to reduce the length from 36 to 22 characters.

Answered By SmartIDCreator73 On

Check out NanoID! It's only 10 characters long, and it can generate IDs quickly with a low chance of collision. Some alternatives even keep IDs to just 7 characters, helping you create shorter URLs.

Answered By PracticalDev01 On

Whether it's an anti-pattern really depends on your needs. If URL length is a business concern, then maybe encoding makes sense. But adding complexity for the sake of a shorter URL might not be worth it. Perhaps consider a different identifier altogether?

Answered By BloggingNinja88 On

Why not use slugs instead? If these are for blog posts, you could auto-generate slugs from the titles. It makes for much cleaner and more semantic URLs.

Answered By SEOExpert99 On

Encoding adds unnecessary complexity for both server and client. It’s simpler to just use numeric IDs and slugs for better SEO. Think about using an auto-incremented ID along with a slug, especially if you're only dealing with a few thousand entries!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.