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?
-
This is a browser side issue, browser cached your page, so when click back button you still see the cached page. – STA Jul 02 '20 at 10:24
-
Is it possible to go around this? – Just Another Guy Jul 02 '20 at 10:31
1 Answers
The page is being loaded from a cache there would be 2 ways to solve this
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.
(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

- 884
- 9
- 18