php - Load Laravel View with Placeholders before SQL Query Completes
764
I'm loading a view which contains results from a large SQL query which takes 10 seconds to load. It concerns users because it seems like the server is unresponsive.
Can I load the view with SQL placeholders and load the SQL results on the page after the view is loaded?
//web.php route
Route::get('/results', '[email protected]');
//[email protected]
public function showResults() {
$vw = Cache::remember('vwResultsCache',3,function(){
return $query = DB::table('vwResults')->first();
});
$count1 = $vw->count1;
$count2 = $vw->count2;
$count3 = $vw->count3;
return view ('backend.results', compact('count1','count2','count3'));
}
//backend.results view
<span> Welcome to the page</span>
<tbody>
<tr>
{{--count1--}}
<td>
{{$count1}}
</td>
{{--count2--}}
<td>
{{$count2}}
</td>
{{--count3--}}
<td>
{{$count3}}
</td>
</tr>
</tbody>