DEV Community

Cover image for Building an SEO-Friendly Slug Generator for JustBlogged
Arbab Tahir
Arbab Tahir

Posted on

Building an SEO-Friendly Slug Generator for JustBlogged

When we started building JustBlogged, we noticed a small but recurring problem.

Many creators publish great content but pay very little attention to their URLs. Some platforms generate long or unclear slugs automatically, while others require users to edit them manually.

Since JustBlogged aims to simplify publishing, we decided to build a free Slug Generator that creates clean, readable, and SEO-friendly URLs in seconds.

Why Slugs Matter

A URL is often the first thing people see before opening your content.

Compare these two examples:

/post?id=48392
Enter fullscreen mode Exit fullscreen mode

vs.

/how-to-start-a-tech-blog
Enter fullscreen mode Exit fullscreen mode

The second immediately tells both users and search engines what the page is about.

Our Approach

We wanted the generator to:

  • Convert text to lowercase.
  • Replace spaces with hyphens.
  • Remove unnecessary punctuation.
  • Produce clean, readable URLs.
  • Be fast enough to update instantly while typing.

A simplified version of the logic looks like this:

function slugify(text) {
  return text
    .toLowerCase()
    .trim()
    .replace(/[^\w\s-]/g, "")
    .replace(/\s+/g, "-")
    .replace(/-+/g, "-");
}
Enter fullscreen mode Exit fullscreen mode

In production, there are additional edge cases to consider, such as Unicode characters, accented letters, emojis, duplicate slugs, and reserved routes.

What We Learned

Building this feature reminded us that publishing isn't just about writing.

Small details like URL structure, readability, and workflow all contribute to a better publishing experience.

Sometimes the smallest features save the most time because they're used every single day.

Try It

If you're a blogger, developer, or content creator, you can try our free Slug Generator here:

👉 https://justblogged.com/tools/slug-generator

We're continuously improving our creator tools, so we'd love to hear your feedback and ideas for what we should build next.

Top comments (2)

Collapse
 
citedy profile image
Dmitry Sergeev

do you handle duplicate slugs by adding a number at the end or just throwing a random string in there?

Collapse
 
citedy profile image
Dmitry Sergeev

do you handle duplicate slugs by appending a number or something, or just letting the DB throw an error?