title: MVC 4 - GZIP compression of JSON ajax action result
body: <h2>The problem</h2>
  
  <p>I have a Telerik MVC UI grid on an MVC 4 app running on IIS 7.5 that can potentially return a large amount of JSON data via AJAX, in extreme cases 800kb or more. As the payload can be large, I want to GZIP it. For the life of me, I cannot get it working. </p>
  
  <p>The controller action is:</p>
  
  <pre><code>public ActionResult _CustomBinding([DataSourceRequest] DataSourceRequest request, SearchMemberModel search)
  {
      //Do some stuff
  
     return Json(result);
  }
  </code></pre>
  
  <p>Fiddler reports:
  <img src="https://i.stack.imgur.com/aU46S.png" alt="enter image description here"></p>
  
  <h2>What has been tried</h2>
  
  <p>I have ensured dynamic and static compression is enabled in IIS:</p>
  
  <p><img src="https://i.stack.imgur.com/9vkMQ.png" alt="enter image description here"></p>
  
  <p>App Web.Config amended:</p>
  
  <pre><code>  &lt;system.webServer&gt;
      &lt;serverRuntime frequentHitThreshold="1" frequentHitTimePeriod="10:00:00" /&gt;
  
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;modules runAllManagedModulesForAllRequests="false"&gt;
        &lt;remove name="FormsAuthentication" /&gt;
      &lt;/modules&gt;
  
      &lt;httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"&gt;
  
        &lt;scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9"  /&gt;
        &lt;dynamicTypes&gt;
          &lt;add mimeType="text/*" enabled="true" /&gt;
          &lt;add mimeType="message/*" enabled="true" /&gt;
          &lt;add mimeType="application/x-javascript" enabled="true" /&gt;
          &lt;add mimeType="application/json" enabled="true" /&gt;
          &lt;add mimeType="*/*" enabled="false" /&gt;
        &lt;/dynamicTypes&gt;
        &lt;staticTypes&gt;
          &lt;add mimeType="text/*" enabled="true" /&gt;
          &lt;add mimeType="message/*" enabled="true" /&gt;
          &lt;add mimeType="application/x-javascript" enabled="true" /&gt;
          &lt;add mimeType="application/atom+xml" enabled="true" /&gt;
          &lt;add mimeType="application/xaml+xml" enabled="true" /&gt;
          &lt;add mimeType="*/*" enabled="false" /&gt;
        &lt;/staticTypes&gt;
      &lt;/httpCompression&gt;
  
      &lt;urlCompression doStaticCompression="true" doDynamicCompression="true" /&gt;
  
    &lt;/system.webServer&gt;
  </code></pre>
  
  <p>I've made sure the <a href="https://stackoverflow.com/questions/2515421/how-to-compress-json-with-asp">ApplicationHost file has the right mime types</a>: </p>
  
  <pre><code>    &lt;add mimeType="application/json" enabled="true" /&gt;
      &lt;add mimeType="application/json; charset=utf-8" enabled="true" /&gt;
      &lt;add mimeType="application/json;charset=utf-8" enabled="true" /&gt;
  </code></pre>
  
  <p>I've tried the <a href="https://stackoverflow.com/questions/6938713/gzip-compression-on-iis-7-5-is-not-working">suggestion here</a> that the serverRuntime frequentHitThreshold needs amending. </p>
  
  <p>Is there something I'm missing?</p>