title: JSON serialization is very slow when compared to XML
body: <p>I have a webapi service that I need to access from web app</p>
  
  <p>If I call the webapi url directly (e.g. /api/scrccc/32) it returns data in less then 5 sec, but when called from jquery, it takes more then 5 minutes (!!!) minutes</p>
  
  <p>My ajax call is</p>
  
  <pre><code>j$.ajax({
     type: "GET",
     url: '/api/scrccc/' + id + '?dt=' + new Date().getTime(),
     error: function (jqXHR, status, error) {
         //....         
     },
     success: function (data, status, jqXHR) {
         //....
     }
  });
  </code></pre>
  
  <p>This happens with javascript console (firebug) open or closed, and in Chrome and FF</p>
  
  <p>Anyone has any idea why this happens?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here are the timings in Chrome with Jquery call:</p>
  
  <p><img src="https://i.stack.imgur.com/QEHBY.png" alt="Timimgs in Chrome - with jquery"></p>
  
  <p>and the timings in Chrome with direct access to url in address bar</p>
  
  <p><img src="https://i.stack.imgur.com/maFAt.png" alt="Timimgs in Chrome - direct url call"></p>
  
  <p>... and timimgs in browser with timestamp also</p>
  
  <p><img src="https://i.stack.imgur.com/KxULK.png" alt="Timimgs in Chrome - direct url call with timestamp param"></p>
  
  <p><strong>EDIT - June 1</strong></p>
  
  <p>I realized there is a difference between calling the webapi from ajax and from browser's address bar:
  - ajax call requests response as json
  - browser requests response as XML</p>
  
  <p>So I tested both requests in Postman, with json and xml response and the findings puzzled me: request with xml response took 1261 ms while json response took 47000 ms (!!!)</p>
  
  <p>(The timings shown in Chrome console were with local IIS Express, while latest timings shown in Postman are with real app on real web server over internet, that's why they are different, but the scale remains)</p>
  
  <p><img src="https://i.stack.imgur.com/BE1k5.png" alt="XML response"></p>
  
  <p><img src="https://i.stack.imgur.com/OZagh.png" alt="enter image description here"></p>
  
  <p>So, indeed, the problem is at the server side, as some suggested, but not in the actual application code providing data, but instead at the serialization point.</p>
  
  <p>My Webapi is 2.1 (version 5.1.2), and Json.Net version 6.0.3 (both are latest versions)
  I have no special settings to use any particular json serializer, so, as I know, WebApi uses Json.Net.</p>
  
  <p>Any idea what could cause such a HUGE difference in serialization time?</p>
  
  <p>Thanks</p>