<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Curious Developer</title>
    <description>The latest articles on DEV Community by Curious Developer (@nim_118).</description>
    <link>https://dev.to/nim_118</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F894869%2F51368430-a44e-4109-8da8-fda233fdef1f.jpg</url>
      <title>DEV Community: Curious Developer</title>
      <link>https://dev.to/nim_118</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nim_118"/>
    <language>en</language>
    <item>
      <title>Optimizing Article URLs for Performance and SEO: Moving Beyond Slugs</title>
      <dc:creator>Curious Developer</dc:creator>
      <pubDate>Wed, 09 Apr 2025 09:28:18 +0000</pubDate>
      <link>https://dev.to/nim_118/optimizing-article-urls-for-performance-and-seo-moving-beyond-slugs-49m1</link>
      <guid>https://dev.to/nim_118/optimizing-article-urls-for-performance-and-seo-moving-beyond-slugs-49m1</guid>
      <description>&lt;p&gt;When building content-heavy platforms like news websites, URL design plays a crucial role in both SEO and backend performance. Many legacy systems and modern CMSs still rely on slug-based URLs to uniquely identify and route to an article. While great for human readability and SEO, this approach can significantly slow down backend performance at scale.&lt;/p&gt;

&lt;p&gt;Let’s break down the issue and look at a more efficient alternative.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem with Slug-Based URLs
&lt;/h2&gt;

&lt;p&gt;Here’s a typical slug-based article URL:&lt;br&gt;
&lt;code&gt;https://example.com/news/international/slug-title-goes-here&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In systems using this approach:&lt;/p&gt;

&lt;p&gt;The slug (string in the URL) is used to find the article in the database.&lt;/p&gt;

&lt;p&gt;This typically results in full-text or indexed searches, which can be costly in terms of performance as the data grows.&lt;/p&gt;

&lt;p&gt;If the slug changes (e.g., after a headline update), old links can break or will result in 404 for the indexed urls. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution: Timestamp-Based Numeric IDs
&lt;/h2&gt;

&lt;p&gt;To solve this, we moved to a &lt;strong&gt;hybrid URL structure&lt;/strong&gt; using both slug and a 10-digit unique numeric ID appended at the end. Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://example.com/news/international/slug-title-1712659384&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here’s how it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The last segment (1712659384) is a 10-digit numeric ID, generated using the Unix timestamp (in seconds).&lt;/li&gt;
&lt;li&gt;This ID serves as the primary key to fetch the article directly from the database.&lt;/li&gt;
&lt;li&gt;The slug is optional for SEO and user readability, but article lookup relies only on the ID.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why This Works
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fast Lookups:&lt;/strong&gt; Numeric ID allows for fast, indexed database queries (e.g., by _id or article_id).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SEO-Friendly&lt;/strong&gt;: Slugs still exist for users and search engines, but aren’t part of the lookup logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stable URLs:&lt;/strong&gt; Even if the title or slug changes, the article ID ensures the URL remains valid.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiple Access Points:&lt;/strong&gt; Articles can be accessed from various URLs with different slugs, as long as the ID remains the same.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Canonical Tag Usage:&lt;/strong&gt; To avoid SEO penalties for duplicate content across different slug variations, set a canonical URL using the original permalink.
&lt;code&gt;&amp;lt;link rel="canonical" href="https://example.com/news/initial-slug-1712659384" /&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time-Encoded:&lt;/strong&gt; Using timestamps ensures uniqueness per second and gives an approximate idea of when the article was created.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Implementation Tips
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;ID Generation:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;const articleId = Math.floor(Date.now() / 1000); // 10-digit Unix timestamp&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;URL Structure:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;const permalink =&lt;/code&gt;/news/${slug}-${articleId}&lt;code&gt;;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Backend Routing:&lt;/strong&gt;
Extract the numeric ID from the URL using regex:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;const id = req.params.slugOrId.match(/(\d{10})$/)[1];&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fallback Logic:&lt;/strong&gt;&lt;br&gt;
If ID is not found, optionally fallback to slug-based search (but cache it).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SEO Best Practices:&lt;/strong&gt;&lt;br&gt;
Always include the original permalink in a canonical tag to consolidate SEO ranking to a single source.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;This small shift in URL design can dramatically improve performance and maintain SEO benefits. It’s especially powerful for high-traffic sites like news platforms where quick and reliable article lookup is critical.&lt;/p&gt;

&lt;p&gt;Have you tried similar strategies in your app or CMS? Let’s discuss in the comments!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
