js: remove 301 redirect cache fix

This code was required because we messed-up in the past regarding
caching headers. This is not required anymore because the caching set
has expired, so no well behaving user-agent should have remains.

This represents something like 240k requests to the backend (not the
cache) over two weeks. Server load was minimal because generating those
responses is really fast.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
This commit is contained in:
Théo Lebrun 2024-12-19 17:20:00 +01:00
parent 9033e80fb2
commit 972fdd73e1
2 changed files with 1 additions and 23 deletions

View file

@ -319,27 +319,6 @@ function setupGoToTop() {
}); });
} }
// 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
function fix301() {
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);
}
}
function randomChoice(arr) { function randomChoice(arr) {
return arr[Math.floor(Math.random() * arr.length)]; return arr[Math.floor(Math.random() * arr.length)];
} }
@ -425,5 +404,4 @@ document.addEventListener('DOMContentLoaded', _ => {
setupAutoscrollingPrevention(); setupAutoscrollingPrevention();
setupAnchorOffsetHandler(); setupAnchorOffsetHandler();
setupGoToTop(); setupGoToTop();
fix301();
}); });

View file

@ -75,7 +75,7 @@
</span> </span>
</footer> </footer>
</div> </div>
<script src="/static/script.js?v=15"></script> <script src="/static/script.js?v=16"></script>
<script src="/static/dynamic-references.js?v=4"></script> <script src="/static/dynamic-references.js?v=4"></script>
<script src="/static/autocomplete.js" project="{{ current_project }}"></script> <script src="/static/autocomplete.js" project="{{ current_project }}"></script>
</body> </body>