Convert text into URL-friendly slug strings.
A "slug" is the part of a URL that identifies a particular page in an easy-to-read form. The term originated in the newspaper industry, where a short name was given to an article while it was in production.
In the early days of the web, URLs were driven entirely by database IDs: example.com/article?id=8472. While functional for servers, this tells the user (and Googlebot) absolutely nothing about what is on the page.
Modern frameworks use routing to support semantic URLs: example.com/blog/how-to-bake-bread. This is vastly superior because the keywords in the URL actively contribute to the page's search ranking.
To create a valid slug that won't break browsers or servers, the raw title string must be heavily normalized.
-). Note: Google specifically treats hyphens as word separators. Underscores (_) are generally discouraged for SEO.? or &) must be stripped out, as they have reserved meanings in HTTP requests.If a user types "Café & Résumé", a naive regex replace might just strip the accented characters, resulting in "caf-rsum". This ruins the SEO value.
Proper slug generators use Unicode normalization (like String.prototype.normalize("NFD")) to decompose accented characters into their base character plus the accent mark. It can then safely strip the floating accent marks, resulting in the perfect slug: "cafe-resume".
Why are hyphens (-) preferred over underscores (_) when generating slugs for SEO?