Using an edge handler for legacy URL redirects?

Hi there,

we are struggling with a large number (~2,500) of legacy redirects and adverse effects on TTFB on our site https://bi-medien.de, similar to the issue described here: How does redirect caching work? - #12 by luke. Google suggests to keep 301-redirects for at least a year so it isn’t really an option to just drop them altogether for the sake of the site’s performance. But at the same time, the current TTFBs of 500-1200ms on many requests are inacceptable.

The legacy URLs that we are dragging along have a very uncommon but specific pattern: all page paths only have a single level and all have an ending in “.bi”, for example “/random-path-to-some-page.bi”.

Would it be possible and sensible to use an edge handler to redirect these legacy URLs? My idea in pseudo code:

import redirect_map from ./data.json
export async function onRequest(event) {
    const request = await event.getRequest()
    if (request.url.includes("bi")) {
      // ...look up redirect in redirect_map and return HTTP 301 with new URL
    }
}

My thinking is that this would catch all requests to legacy URLs that need to be redirected while not hurting new URLs – because the “.bi” string never occurs in them. At the same time, because 99,9% of requests don’t go to legacy URLs, it would save checking for redirects for all of these requests and should vastly improve TTFB and site performance in these cases?!

Does this make sense at all? Would you recommend to try it out?

Hey there, @Durcheinander :wave:

Thanks so much for your patience here! I have shared you question with the team that works with edge handlers, and I hope to have more information for you soon.

Hi @Durcheinander!

Edge Handlers should allow you to make some of those advanced redirect cases easier, yes.
I’m still not very sure what you’re trying to do here:

look up redirect in redirect_map

This sounds like you would need the long list of redirects still? How would this code improve the situation?
Can you think of a solution where you don’t need a lookup in a large list?

Your assumption about limiting the impact to only those legacy urls sounds correct - if you’re able to store that list inside your edge handler code. If you still need to store it with us, you don’t get any benefits and we also don’t give you access to your list of redirects like that.

You can try out edge handlers locally to test some actual code though:

Hi @marcus,

well, I could reduce the lookup over the current situation by about 150 entries because the Edge Handler would allow me to do things like lowercasing. (Don’t ask me why but the legacy system we used in the past generated lower and uppercase URLs for the same pages in some cases and these URLs are somehow out there as backlinks :-/)
But most importatnly, the long list would only need to be used for requests that concern legacy URLs – which I expect to be the case for maybe 0.5% of all requests. And yes, I was thinking to store the list in the edge handler code.

Thank you for the pointer to testing Edge Handlers locally, I’ll try that out and get back to you.

1 Like