Optimizing IIS 7.5 for Static Content Delivery: Performance Tweaks and Configuration Best Practices


3 views

When setting up a cookie-free domain for serving static content (like images, CSS, and JavaScript), optimizing IIS 7.5 can significantly improve performance. Since the domain won't handle dynamic content, several configurations can be adjusted to reduce overhead and maximize throughput.

For a static-only site, disabling ASP.NET and other dynamic content modules reduces memory usage and processing overhead. Here's how to disable ASP.NET at the site level:

<configuration>
  <system.webServer>
    <modules>
      <remove name="ScriptModule-4.0" />
      <remove name="UrlRoutingModule-4.0" />
    </modules>
  </system.webServer>
</configuration>

Compressing static files reduces bandwidth usage and speeds up delivery. Enable it in applicationHost.config:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
  <staticTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="application/javascript" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
  </staticTypes>
</httpCompression>

Setting proper cache headers ensures browsers cache static content efficiently. Add this to web.config:

<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>

Since no dynamic content is served, disable session state in web.config:

<system.web>
  <sessionState mode="Off" />
  <pages enableViewState="false" />
</system.web>

For even better performance, consider using a custom handler for static files. Here's an example in web.config:

<system.webServer>
  <handlers>
    <add name="StaticFileHandler" path="*" verb="GET,HEAD" 
         type="System.Web.StaticFileHandler" resourceType="File" />
  </handlers>
</system.webServer>

Enable kernel-mode caching for frequently accessed files:

<system.webServer>
  <outputCache enabled="true" enableKernelCache="true" />
</system.webServer>

By implementing these optimizations, your static content domain will deliver files faster with lower server overhead. Test each change to ensure compatibility with your specific setup.


When serving static assets (CSS, JavaScript, images), using a cookie-free subdomain like static.yourdomain.com provides two major benefits:

1. Eliminates unnecessary cookie transmission (average 300-500 bytes per request)
2. Enables parallel downloads by bypassing browser connection limits per domain

For optimal static content serving, apply these web.config settings:

<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
      <remove fileExtension=".js" />
      <remove fileExtension=".css" />
      <mimeMap fileExtension=".js" mimeType="application/javascript" />
      <mimeMap fileExtension=".css" mimeType="text/css" />
    </staticContent>
    
    <httpCompression>
      <dynamicTypes>
        <add mimeType="text/*" enabled="false" />
      </dynamicTypes>
      <staticTypes>
        <add mimeType="application/javascript" enabled="true" />
        <add mimeType="text/css" enabled="true" />
      </staticTypes>
    </httpCompression>
  </system.webServer>
</configuration>

Since this site only serves static content, disable these modules via ApplicationHost.config:

<location path="static.yourdomain.com">
  <system.webServer>
    <modules>
      <remove name="Session" />
      <remove name="WindowsAuthentication" />
      <remove name="FormsAuthentication" />
      <remove name="UrlAuthorization" />
    </modules>
  </system.webServer>
</location>

Configure kernel-mode caching for maximum throughput:

appcmd.exe set config "static.yourdomain.com" 
-section:system.webServer/serverRuntime 
/frequentHitThreshold:"1" 
/frequentHitTimePeriod:"00:00:10"
/commit:apphost

Use this PowerShell script to verify your configuration:

$results = 1..100 | ForEach-Object {
    $response = Invoke-WebRequest -Uri "https://static.yourdomain.com/style.css" -Method Head
    [PSCustomObject]@{
        Server = $response.Headers['Server']
        CacheControl = $response.Headers['Cache-Control']
        ContentEncoding = $response.Headers['Content-Encoding']
        ProcessingTime = $response.Headers['X-Powered-By']
    }
}
$results | Group-Object Server, CacheControl | Format-Table -AutoSize

For modern setups, enable HTTP/2 in IIS and consider these CDN-friendly headers:

<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*.yourdomain.com" />
    <add name="Timing-Allow-Origin" value="https://www.yourdomain.com" />
    <add name="Vary" value="Accept-Encoding" />
  </customHeaders>
</httpProtocol>