A slug is a URL-friendly string that serves as a unique identifier for a web resource, typically derived from the resource's title or name. Slugs are created by converting text to lowercase, replacing spaces with hyphens, removing special characters, and truncating to a reasonable length. For example, the title "What Is URL Shortening?" becomes the slug "what-is-url-shortening."
The term "slug" originates from newspaper publishing, where it referred to a short name given to an article during production. In web development, slugs serve the same purpose: they provide a human-readable identifier that can be used in URLs. Web development books on Amazon explain slug generation.
In URL shortening, the concept of a slug applies to custom aliases. When a user creates a short URL with a custom code like "summer-sale," that code is essentially a slug for the shortened link. The same principles of good slug design apply: keep it concise, use meaningful words, and avoid characters that require encoding.
Slug generation must handle edge cases including duplicate slugs (requiring uniqueness enforcement), Unicode characters (requiring transliteration or encoding decisions), reserved words (that might conflict with application routes), and excessively long titles (requiring intelligent truncation). Software design books on Amazon discuss these patterns.