I need to implement a couple Javascript redirects using window.location on my site. This redirect fires in very specific circumstances and I don't want that redirect cached.

I found info about how CloudFlare handles 301s and 302s but how will it respond to JS redirecting?

Thank you!

1 Answer 1


CloudFlare will cache a JS redirect just like it caches a normal HTML page, because a JS redirect is a normal HTML page. If you don't want CloudFlare to cache particular JS redirecting code, I suggest you use a page rule to specify that you do not want the HTML/JS that initiates the redirect cached.

  • Thank you—I'm ok with the destination page being cached by CF. Will the redirect response itself be cached so that future visits to that page will be redirected by CloudFlare to the redirect destination or will the logic in the JS script still run and decide if that user is redirected? Thanks!
    – Vecta
    Apr 5, 2019 at 16:51
  • In the case of a JS redirect, the redirect is the originating page and JS, with its 200 response(s). There is no redirect status code in a JS redirect, because the redirect is handled in the script itself rather than by any server status code. Since the redirect is the page with the JS, whether you cache that page/JS will determine whether the redirect code is cached. In any case, the JS will run every time the user visits the page that has the JS on it - window.location doesn't do anything funky to the browser's caching behavior. Apr 5, 2019 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.