Introduction to IIS Compression on Windows Server 2019

HTTP compression reduces the size of responses sent from IIS to clients, significantly reducing bandwidth consumption and improving page load times, particularly for text-based content (HTML, CSS, JavaScript, XML, JSON). IIS 10 on Windows Server 2019 supports two types of compression: Static Compression (compresses static files once and caches the compressed version on disk) and Dynamic Compression (compresses responses generated dynamically by applications on each request). Both use gzip and deflate encoding by default, with Brotli compression available via third-party modules. This guide covers enabling, configuring, and tuning both compression types.

Install Compression Features

# Install IIS static and dynamic compression roles
Install-WindowsFeature `
    -Name Web-Stat-Compression, Web-Dyn-Compression `
    -IncludeManagementTools

# Verify installation
Get-WindowsFeature -Name Web-Stat-Compression, Web-Dyn-Compression | 
    Select-Object Name, InstallState | Format-Table

# Check compression modules are loaded in IIS
Get-WebConfiguration -Filter "system.webServer/globalModules/add" |
    Where-Object name -match "Compress" | Select-Object name, image

Enable Static Compression

Static compression compresses files like .html, .css, .js and stores the compressed versions in a disk cache. On subsequent requests for the same file, IIS serves the cached compressed version without re-compressing. This is highly CPU-efficient for sites serving the same static files repeatedly.

# Enable static compression at server level
Set-WebConfigurationProperty `
    -PSPath "IIS:" `
    -Filter "system.webServer/httpCompression" `
    -Name "doStaticCompression" -Value $true

# Set the static compression cache folder
Set-WebConfigurationProperty `
    -PSPath "IIS:" `
    -Filter "system.webServer/httpCompression" `
    -Name "directory" -Value "%SystemDrive%inetpubtempIIS Temporary Compressed Files"

# Set compression level (1=fastest, 9=best compression, default=7)
Set-WebConfigurationProperty `
    -PSPath "IIS:" `
    -Filter "system.webServer/httpCompression/scheme[@name='gzip']" `
    -Name "staticCompressionLevel" -Value 7

# View current httpCompression settings
Get-WebConfiguration -Filter "system.webServer/httpCompression" | Format-List

Enable Dynamic Compression

Dynamic compression compresses responses generated by ASP.NET, PHP, and other server-side applications on each request. Because the response content changes per request, it cannot be cached to disk. Dynamic compression does consume more CPU than static compression, so tuning the CPU threshold is important to prevent compression from degrading performance under load.

# Enable dynamic compression at server level
Set-WebConfigurationProperty `
    -PSPath "IIS:" `
    -Filter "system.webServer/httpCompression" `
    -Name "doDynamicCompression" -Value $true

# Set dynamic compression level (lower = less CPU, less compression)
Set-WebConfigurationProperty `
    -PSPath "IIS:" `
    -Filter "system.webServer/httpCompression/scheme[@name='gzip']" `
    -Name "dynamicCompressionLevel" -Value 4   # Balance of speed and compression

# Set CPU usage threshold — disable dynamic compression above this CPU %
Set-WebConfigurationProperty `
    -PSPath "IIS:" `
    -Filter "system.webServer/httpCompression" `
    -Name "dynamicCompressionDisableCpuUsage" -Value 90   # Disable above 90% CPU
Set-WebConfigurationProperty `
    -PSPath "IIS:" `
    -Filter "system.webServer/httpCompression" `
    -Name "dynamicCompressionEnableCpuUsage" -Value 50    # Re-enable when below 50%

Enable Compression at Site Level

Even with server-level compression enabled, you must also enable it at the site level in the URL compression settings. Sites inherit server defaults but can override them:

# Enable both compression types for a specific site
Set-WebConfigurationProperty `
    -PSPath "IIS:SitesDefault Web Site" `
    -Filter "system.webServer/urlCompression" `
    -Name "doStaticCompression" -Value $true

Set-WebConfigurationProperty `
    -PSPath "IIS:SitesDefault Web Site" `
    -Filter "system.webServer/urlCompression" `
    -Name "doDynamicCompression" -Value $true

# Verify
Get-WebConfiguration -Filter "system.webServer/urlCompression" `
    -PSPath "IIS:SitesDefault Web Site" | Format-List

Configure MIME Types for Compression

IIS only compresses content types that are explicitly listed in the compression configuration. By default, HTML, CSS, JavaScript, and text files are included, but JSON, XML, SVG, and fonts may need to be added:

# View current static compression MIME types
Get-WebConfiguration -Filter "system.webServer/httpCompression/staticTypes/add" |
    Select-Object mimeType, enabled | Format-Table

# Add JSON to static compression
Add-WebConfiguration -Filter "system.webServer/httpCompression/staticTypes" `
    -PSPath "IIS:" `
    -Value @{mimeType="application/json"; enabled="True"}

# Add SVG
Add-WebConfiguration -Filter "system.webServer/httpCompression/staticTypes" `
    -PSPath "IIS:" `
    -Value @{mimeType="image/svg+xml"; enabled="True"}

# Add XML
Add-WebConfiguration -Filter "system.webServer/httpCompression/staticTypes" `
    -PSPath "IIS:" `
    -Value @{mimeType="application/xml"; enabled="True"}

# Add JSON to dynamic compression
Add-WebConfiguration -Filter "system.webServer/httpCompression/dynamicTypes" `
    -PSPath "IIS:" `
    -Value @{mimeType="application/json"; enabled="True"}

Configure Minimum File Size for Compression

Compressing very small files wastes CPU time for negligible bandwidth savings. Set a minimum file size threshold:

# Set minimum file size to 2048 bytes (2KB) for static compression
Set-WebConfigurationProperty `
    -PSPath "IIS:" `
    -Filter "system.webServer/httpCompression" `
    -Name "minFileSizeForComp" -Value 2048

# Verify
Get-WebConfigurationProperty `
    -PSPath "IIS:" `
    -Filter "system.webServer/httpCompression" `
    -Name "minFileSizeForComp"

Configure Disk Cache for Static Compression

The static compression cache needs adequate disk space. Monitor and tune cache settings:

# View the compression cache directory
Get-WebConfigurationProperty `
    -PSPath "IIS:" `
    -Filter "system.webServer/httpCompression" `
    -Name "directory"

# The cache is managed by IIS automatically — view contents
$cacheDir = "$env:SystemDriveinetpubtempIIS Temporary Compressed Files"
if (Test-Path $cacheDir) {
    Get-ChildItem -Path $cacheDir -Recurse -File | 
        Measure-Object -Property Length -Sum |
        ForEach-Object { Write-Host "Cache size: $([math]::Round($_.Sum/1MB, 2)) MB" }
}

# Clear compression cache (IIS will recreate on next request)
if (Test-Path $cacheDir) {
    Get-ChildItem -Path $cacheDir -Recurse -File | Remove-Item -Force
    Write-Host "Compression cache cleared"
}

Verify Compression is Working

# Test compression from PowerShell using WebRequest
$headers = @{"Accept-Encoding" = "gzip, deflate"}
$response = Invoke-WebRequest `
    -Uri "http://www.corp.example.com/index.html" `
    -Headers $headers

Write-Host "Content-Encoding: $($response.Headers.'Content-Encoding')"
Write-Host "Content-Length: $($response.Headers.'Content-Length')"

# Use curl to test compression and see raw headers
# curl -I -H "Accept-Encoding: gzip" http://www.corp.example.com/

# Check IIS performance counters for compression statistics
Get-Counter "Web Service(_Total)Total Gzip Requests" -SampleInterval 10 -MaxSamples 3
Get-Counter "HTTP Service Url Groups(_Total)Requests/Sec" -SampleInterval 10 -MaxSamples 3

Disable Compression for Specific Paths

For already-compressed content (images, zip files, video) or for paths where bandwidth is not a concern, disable compression to save CPU:

# Disable compression for a specific virtual directory or path via web.config:
# 
#   
#     
#   
# 

Set-WebConfigurationProperty `
    -PSPath "IIS:SitesDefault Web Siteuploads" `
    -Filter "system.webServer/urlCompression" `
    -Name "doStaticCompression" -Value $false

Set-WebConfigurationProperty `
    -PSPath "IIS:SitesDefault Web Siteuploads" `
    -Filter "system.webServer/urlCompression" `
    -Name "doDynamicCompression" -Value $false

Summary

IIS compression on Windows Server 2019 is one of the most cost-effective performance improvements available — it typically reduces text response sizes by 60–80% with minimal CPU overhead. Static compression with disk caching is essentially free after the first request. Dynamic compression requires careful CPU threshold configuration to avoid degrading performance under heavy load. Ensure your JSON, SVG, and XML MIME types are added to the compression list, exclude already-compressed binary content, and set a minimum file size threshold to avoid wasting CPU on trivially small responses.