Laravel 5.1 ajax get requests takes drastically longer time to load the page
<p>I am using laravel 5.1 and i want to make ajax get request calls as its a admin dashboard.</p>

<p>I am using DB queries for my response return and getting the data on the tables and graph using ajax, since i have dates filter and other filters.</p>

<p>My app is getting too slow to load when i click on apply button which makes different types of request on the page.</p>

<p>So this is what i am doing.</p>

<pre><code>  $data = DB::table("leads")
-&gt;select((array(DB::Raw('DATE(leads.created_at) as creation'), 
DB::Raw("COUNT(leads.id) as total_leads"), DB::Raw("leads.id as id"),DB::Raw("leads.customer_name as customer_name" ),DB::Raw("leads.city as city"), DB::Raw("leads.email as email"),DB::Raw("leads.contact as contact"),DB::Raw("leads.source as source"),DB::Raw("leads.campaign_name as campaign"),DB::Raw("leads.ad_group as ad_group"),DB::Raw("leads.ad as ad"),DB::Raw("leads.keyword as keyword") )))
-&gt;where("leads.created_at","&gt;=",$startDate)
-&gt;where("leads.created_at","&lt;",$endDate)
-&gt;groupBy("leads.created_at")
-&gt;orderBy("leads.created_at","desc")
-&gt;get();

 return view("dashboard",compact("data"));
</code></pre>

<p>Now if i use this this query to get the ajax call, which look like this</p>

<pre><code>  $(document).ready(function(){
  $(".applyBtn").on("click",function(){

  var i = $('input[name="daterangepicker_start"]').val();
  var e = $('input[name="daterangepicker_end"]').val();
  console.log(i);

  console.log($("input[id=daterangepicker_start1]").val($('input[name="daterangepicker_start"]').val()));
    console.log($("input[id=daterangepicker_end1]").val($('input[name="daterangepicker_end"]').val()));
  var data = "daterangepicker_start="+i+"&amp;daterangepicker_end="+e;
  $.ajax({
    type:"GET",
    data:data,
    url:'{{ URL::to("/date1") }}',
    success:function(data)
      {
    $("#ack").html(data);

      }
  })
</code></pre>

<p>I am returning another blade template to replace the div ack. </p>

<p>This thing works great in localhost and its working quite faster than its loading on the server,but when i loaded this on linode server, this queries get too slow to work. I have installed the debugbar and it says 400 ms for loading all the queries. Can there be any configuration problem on the server, since its using apache as it was configured before only.</p>

<p>I have too many DB queries on the several pages, say dashboard,leads page.</p>

<p>What should i need to do for optimizing my laravel5.1 app, and how can i serve it easily using ajax.</p>

<p>Please let me know any solutions ,so that the loading request made by ajax take less time to load the other blade template which pulls the data view.</p>