N
Nuxt2mo ago
Matthias

Disable SWR caching for redirects

Hello I am useing Nuxt 3 for my projects and enabled swr-caching via route rules in my nuxt config leveraging a wildcard. This works great but I also have a rout middleware that handles redirects using NavigateTo. The redirects are fetched dynamically so are not known. I found that all my redirects are being cached with swr. How can I disable the cache in my middleware when I redirect?
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @Matthias. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To address your issue with SWR caching for redirects in Nuxt 3, there's a recent fix that should solve this problem. The Nuxt team has implemented a change to prevent marking redirected routes as prerendered, which was causing the caching issue you're experiencing. This fix is available in Nuxt 3.8.1 and later versions. Here's what you need to know: 1. Update to the latest version of Nuxt 3 (at least 3.8.1) if you haven't already. 2. The fix automatically prevents caching of redirected routes, so you shouldn't need to make any changes to your existing code. This change was implemented in a pull request that specifically addresses this issue: fix(nuxt): don't mark redirected routes as prerendered (https://github.com/nuxt/nuxt/pull/23707). If you're still experiencing issues after updating, you might want to check your routeRules configuration to ensure it's not conflicting with this new behavior. For more information on route rules and caching in Nuxt 3, you can refer to the Nuxt documentation on Hybrid Rendering (https://nuxt.com/docs/guide/concepts/rendering#hybrid-rendering). If you need more fine-grained control over caching behavior, you might also want to look into using the respectNoSSRHeader experimental feature, which allows disabling Nuxt SSR responses by setting the x-nuxt-no-ssr header. You can find more information about this in the Nuxt documentation on Experimental Features (https://nuxt.com/docs/guide/going-further/experimental-features#respectnossrheader). Remember to test thoroughly after making any changes to ensure your redirects and caching behave as expected. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@230344366575714316> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Matthias
MatthiasOP2mo ago
@kapa.ai I am already using Nuxt Version 3.12.4
Want results from more Discord servers?
Add your server