Fix incorrectly issued 301 redirects on latest for project roots

This commit adds a small piece of Javascript code to force browsers to forget
about incorrectly issued 301 redirects from "latest" versions.
This code only runs for root project paths (i.e. `/linux/v6.10.2/source`, but
not `/linux/v6.10.2/source/arch`) - other links with "latest" will remain
broken for people who visited them (at least until they clear their cache).
This commit is contained in:
Franciszek Stachura 2024-08-05 15:02:43 +02:00
parent b1ce7d1654
commit 22296b6cf8
2 changed files with 20 additions and 1 deletions

View file

@ -162,4 +162,23 @@ window.requestAnimationFrame(offsetAnchor)
// in case of slow rendering very long pages. // in case of slow rendering very long pages.
window.onload = function () { window.onload = function () {
window.requestAnimationFrame(offsetAnchor) window.requestAnimationFrame(offsetAnchor)
// fix incorrectly issued 301 redirect
// https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
// https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect
// TODO: remove after 10.2024
let path = location.pathname.split('/');
if (path.length == 4) {
path[2] = 'latest';
let newPath = path.join('/');
fetch(newPath, {
cache: 'reload',
redirect: 'manual',
// this is to make sure that varnish will cache the response,
// by default fetch sends no-cache in both headers if cache='reload'
headers: {'Cache-Control': 'max-age=86400', 'Pragma': ''}
})
.then(console.log)
.catch(console.error);
}
} }

View file

@ -44,7 +44,7 @@
<span class="poweredby">powered by <a target="_blank" href="https://github.com/bootlin/elixir">Elixir 2.2</a></span> <span class="poweredby">powered by <a target="_blank" href="https://github.com/bootlin/elixir">Elixir 2.2</a></span>
</footer> </footer>
</div> </div>
<script src="/script.js?v=3"></script> <script src="/script.js?v=4"></script>
<script src="/dynamic-references.js?v=4"></script> <script src="/dynamic-references.js?v=4"></script>
<script src="/autocomplete.js" project="{{ current_project }}"></script> <script src="/autocomplete.js" project="{{ current_project }}"></script>
</body> </body>