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:
parent
b1ce7d1654
commit
22296b6cf8
2 changed files with 20 additions and 1 deletions
|
|
@ -162,4 +162,23 @@ window.requestAnimationFrame(offsetAnchor)
|
|||
// in case of slow rendering very long pages.
|
||||
window.onload = function () {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
<span class="poweredby">powered by <a target="_blank" href="https://github.com/bootlin/elixir">Elixir 2.2</a></span>
|
||||
</footer>
|
||||
</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="/autocomplete.js" project="{{ current_project }}"></script>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Reference in a new issue