1

So we have a portion of our website as a React.js website. The rest is a Legacy site. After taking the user thru a few steps on a wizard, we transfer the user to our Legacy Page. In test its found that when the back browser button is pressed in the Legacy page, then we return to the previous React page, but none of the code in the React page runs. I've proven this by putting alerts and the code is simply not being run. What's happening is that the page is getting displayed with all the previous rendered output, but without any of the code running. So not sure how/where its getting cached.

I've checked the Cache-Control headers on the React page, and its set to Cache-Control: max-age=0, so the Browser should not be caching the page.

Even if there was any code in our legacy app using history.back() then i've tested that history.back() still makes the code to run on the page being moved back to.

So a bit of a mystery as to where its getting cached. Any thoughts as to what may be the issue?

Mickey Puri
  • 835
  • 9
  • 18
  • Does this answer your question? [After travelling back in Firefox history, JavaScript won't run](https://stackoverflow.com/questions/2638292/after-travelling-back-in-firefox-history-javascript-wont-run) – Heretic Monkey Aug 10 '22 at 21:18

2 Answers2

0

As mentioned you are using React.js for your project, I think the best solution for your problem is to use React Router. This will render your components according to your current route. In case you are using the case route for the legacy page then, you will have to think for some other alternatives

Nikhil
  • 56
  • 1
  • 9
0

On December 6th, 2021, Chrome 96 was released, it has a feature called bfcache, or rather back / forward cache and this is different to the Http cache. This caches the entire page in memory,including the Javascript heap, so its like a pause on the page. This is a browser optimisation and is the reason when you go back to the page using the back button on the browser, no code runs as it simply loads it back into memory including all the react state.

more info on bfcache

Mickey Puri
  • 835
  • 9
  • 18