A URL slug is the part located at the very end of a URL that refers to a particular page or post on a website. A URL slug also describes what the page or post is about in a few words; e.g. the title of a blog post. It's in an SEO-friendly format as each word in a URL slug is split by a dash
-, so it's readable by both humans and URL crawlers.
A URL slug doesn't necessarily have to be only in English. It can be written in any languages. Therefore, you can make use of it to optimize your website for SEO to rank better in search engines.
For example, the URL slug for this page is slug-generator as you can see in the full URL below.
A URL slug immensely helps describe the content of a page with a few meaningful words so that the user knows what the page they're visiting is about. It's an important part of SEO optimization for ranking in SERPs as well.
Consider the two URLs below. The first one is a traditional URL with a query string specifying the post ID and the second one is a proper slugified URL with text incicating the title of a post.
As you can tell, the latter is more of a user-friendly URL. You get the idea of what the post is about immediately. Moreover, it's one of the factors that help your website rank higher in search engines because web crawlers also read URL slugs like humans do.
Therefore, you should add some keywords to URL slugs to boost up the SEO performance of your website and gain more benefit over your competitors who are not using URL slugs. However, ensure to keep URL slugs short and descriptive so that they can be seen in SERPs clearly especially on a mobile device.
npm install slug
First of all, import the
slug library into your script, and then you can slugify any words or text with it. The process is very straightforward and simple. The returned value will be a URL-safe slugified string as seen in the following which you can use as the URL slug of a blog post.
const slug = require('slug'); const text = 'How to generate a URL slug from a string'; const urlSlug = slug(text); console.log(urlSlug); // how-to-generate-a-url-slug-from-a-string