Whenever I return to history on my Laravel website, the answer I see is this:
{}
When I move to where I was before, it also shows these curly braces.
The problem does not occur if I run the developer tools in Chrome with the "Disable Cache" option. Content-Type of what returned is really application/json . There is no such problem in Firefox.
This is because one of my Mediators. I wrote AjaxJson middleware to translate all Ajax requests to a JSON response. Oddly enough, when I return to history, Google Chrome makes this Ajax request. It contains this header:
X-Requested-With: XMLHttpRequest
And so $request->ajax() returns true .
This is my middleware:
<?php namespace App\Http\Middleware; use Closure; use Illuminate\Http\Response; class AjaxJson { public function handle($request, Closure $next) { $response = $next($request); if (!$request->ajax()) { return $response; } if (!$response instanceof Response) { return $response; } return response()->json($response->getOriginalContent(), $response->status()); } }
What am I doing wrong?
UPDATE
I found out about the no-store value for the Cache-Control response header. This prevents the use of the Chrome cache when you click the back button. I created the middleware for installing Cache-Control as follows:
Cache-Control: private, max-age = 0, no-cache, no-store
Please let me know guys if you know the best way to solve this problem.
source share