<p dir="auto">When multiple versions of the documentation are available, it tends to pollute google results. As a way to prevent that, it would be good to always have the latest stable release available under /current/, and have all previous versions + the master docs contain canonical links to the current docs like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;link rel=&quot;canonical&quot; href=&quot;http://.../current/...&quot; /&gt;"><pre class="notranslate"><code class="notranslate">&lt;link rel="canonical" href="http://.../current/..." /&gt;
</code></pre></div>
<p dir="auto">That way it consolidates all results under the current URL which will always be correct, and it also encourages people linking to docs in blog posts and such to use links that will not rot.</p>
<p dir="auto">/cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/alexcrichton/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/alexcrichton">@alexcrichton</a></p>
<h1 dir="auto">Motivation and Summary</h1>
<p dir="auto">When someone uses a web search engine to find a crate’s documentation, they are likely to wind up on the documentation for a random older version of that crate. This can be confusing and frustrating if they are working on a project that depends on a more recent version of that crate. As an example: in April 2021, a Google search for [rustls serversession] links to version 0.5.5 of that crate, released Feb 2017. A Google search for [rustls clientsession] links to version 0.11.0, released Jan 2019. The latest version is 0.19.0, released Nov 2020.</p>
<p dir="auto">To fix this, I propose that doc.rs’s URL structure should be more like crates.io: Each crate should have an unversioned URL (docs.rs/rustls/latest) that always shows the docs for the latest version of that crate. There would continue to be versioned URLs like today (<a href="https://docs.rs/rustls/0.19.0/rustls/" rel="nofollow">https://docs.rs/rustls/0.19.0/rustls/</a>), accessible as defined below. I believe this will, over time, lead search engines to more often find the unversioned URL.</p>
<p dir="auto">This is a popular request:</p>
<p dir="auto"><a href="https://github.com/rust-lang/docs.rs/issues/1006" data-hovercard-type="issue" data-hovercard-url="/rust-lang/docs.rs/issues/1006/hovercard">https://github.com/rust-lang/docs.rs/issues/1006<br>
</a><a href="https://github.com/rust-lang/docs.rs/issues/854" data-hovercard-type="issue" data-hovercard-url="/rust-lang/docs.rs/issues/854/hovercard">https://github.com/rust-lang/docs.rs/issues/854<br>
</a><a href="https://github.com/rust-lang/docs.rs/issues/74" data-hovercard-type="issue" data-hovercard-url="/rust-lang/docs.rs/issues/74/hovercard">https://github.com/rust-lang/docs.rs/issues/74<br>
</a><a href="https://github.com/rust-lang/docs.rs/issues/1411" data-hovercard-type="issue" data-hovercard-url="/rust-lang/docs.rs/issues/1411/hovercard">https://github.com/rust-lang/docs.rs/issues/1411<br>
</a></p>
<p dir="auto">It's also a problem that disproportionately affects new users of the language who haven't gotten in the habit of looking for the "go to latest version" link. I know when I was first learning Rust, this problem was a particular headache for me.</p>
<h1 dir="auto">Non-working solutions</h1>
<p dir="auto"><code class="notranslate">&lt;link rel=canonical&gt;</code> is a commonly proposed solution, but <a href="https://datatracker.ietf.org/doc/html/rfc6596" rel="nofollow">it’s not the right fit</a>:</p>
<blockquote>
<p dir="auto">The target (canonical) IRI MUST identify content that is either<br>
duplicative or a superset of the content at the context (referring)<br>
IRI.</p>
</blockquote>
<p dir="auto">Since documentation of different versions is not duplicative, this won’t work. And in fact search engines verify the property, and will disregard canonical links on a site if it does not hold.</p>
<p dir="auto">Here are some links about Google’s handling of canonical:</p>
<p dir="auto"><a href="https://developers.google.com/search/docs/advanced/guidelines/duplicate-content" rel="nofollow">https://developers.google.com/search/docs/advanced/guidelines/duplicate-content</a><br>
<a href="https://developers.google.com/search/docs/advanced/crawling/consolidate-duplicate-urls" rel="nofollow">https://developers.google.com/search/docs/advanced/crawling/consolidate-duplicate-urls</a></p>
<h1 dir="auto">Proposed Solution</h1>
<p dir="auto">For any given crate, <code class="notranslate">https://docs.rs/&lt;crate&gt;/latest</code> should exist and not be a redirect. It should serve the latest version of that crate. Crates.io should be updated so that the unversioned URL for a crate (e.g. <a href="https://crates.io/crates/ureq" rel="nofollow">https://crates.io/crates/ureq</a>) links to the unversioned URL on docs.rs.</p>
<p dir="auto">Sometimes people will want to link to a specific version of the documentation rather than the generic “latest” URL. There will be two ways to do that:</p>
<ul dir="auto">
<li>You can navigate explicitly to the versioned URL, using the version selector tools already available in docs.rs.</li>
<li>Additionally, we should follow GitHub’s UI for when you click on a line number in a source file. When you click on an anchor within a doc page, a little “...” should appear with options to either copy the line or copy a permalink. We may even want to mimic the keystroke to go to a permalink for a page (<code class="notranslate">y</code>).</li>
</ul>
<h1 dir="auto">Caching issues</h1>
<p dir="auto">Currently, only static files are cached. The things that change between versions of a crate are its HTML and some JS (containing JSON data used in displaying the pages). The HTML is currently not cached at all, so invalidating its cache is not a current concern. The JS is also not cached, but it has a unique URL per crate version so easily could be cached.</p>
<p dir="auto">In case we later decide to start caching the HTML: <a href="https://github.com/rust-lang/docs.rs/issues/1006#issuecomment-725650039" data-hovercard-type="issue" data-hovercard-url="/rust-lang/docs.rs/issues/1006/hovercard">The CloudFront rates for cache invalidation are reasonable</a>: $0.005 per invalidation request, and purging a whole subdirectory (like <code class="notranslate">/crates/&lt;crate&gt;/*</code>) is considered a single invalidation request.</p>
<h1 dir="auto">Will it work?</h1>
<p dir="auto">I’m pretty sure it will work. Search engines these days take navigation events heavily into account, so if most navigation events go to an unversioned URL, that will help a lot. Also, once we make this change, the unversioned URLs will start accumulating “link juice,” which will also help a lot.</p>
<p dir="auto">One good demonstration that it will work is that crates.io already follows a scheme like this, and does not have the "links go to old versions" problem at all.</p>