1

I noticed that in my laravel project, when an user goes back using the back arrow at top-left, the user doesn't get updated information from the controller. My question is: How do I force information update from the controller for user, when the user clicks back?

Just Another Guy
  • 77
  • 1
  • 2
  • 9

1 Answers1

1

The page is being loaded from a cache there would be 2 ways to solve this

  1. Send an Ajax request on page load and check some of the user details match the current pages attributes, if they don't match reload the page (or update with JS), if they do then do nothing.

  2. (the hacky way) You'd need to run some JS on page load to check if it loaded from a cache (Talked about here, and has a pretty poor solution) and then force reloading the page if it was cached.

Update 1: You could set a cookie with every request and then check is JS how long is remaining on that cookie and force a page reload if the cookie is too old, although this could cause problems for users with slow connections causing them to reload over and over

Update 2: You can set the Cache-Control header to tell the browser how to cache it (details here)

so your return statement for the view could be like this

$content = view($view_name, $view_data);

return response($content)->header('Cache-Control', 'no-cache, must-revalidate');

Or you could set it up so every response has no cache as described here

Ben Gooding
  • 884
  • 9
  • 18