How to Enable HTTP Compression on IIS Windows Hosting
In this article8 sections
A page of HTML, CSS or JavaScript can be ten times larger than the version a browser needs, because text compresses well. Compression sends the smaller version, and the browser unpacks it. On IIS this is HTTP compression, and it can cut the time a page takes to load, especially for visitors on slow connections. This guide explains what IIS compresses by default, how to turn on compression for static and dynamic content, and how to check that it works without breaking pages that are already compressed by the app.
Siteharbour’s Windows hosting runs IIS 10, and compression is a server feature you can enable for a site. The steps below work in IIS Manager and in the site’s web.config file.
Know what to compress
Compression helps text: HTML, CSS, JavaScript, JSON and SVG. It does little for images in formats that are already compressed, such as JPEG, PNG and WebP, and it can waste CPU on them. Compress text, and leave the images alone. Images are a job for the image size and format, covered in why is my WordPress website slow.
IIS separates two kinds of compression. Static compression applies to files on disk, which it can compress once and cache. Dynamic compression applies to pages the app generates, which it compresses on each request and which costs more CPU.
Step 1: Install the compression features
Compression is an IIS role service. In Server Manager, under the web server role, check that Static Content Compression and Dynamic Content Compression are installed. On a hosted server, your host installs these for you, so ask them to confirm if the options are missing.
Expected: both features are listed as installed. If only static compression is installed, dynamic pages are sent uncompressed, which is the most common cause of a slow page on a fast server.
Step 2: Turn on compression for the site
On IIS, the compression schemes and the list of MIME types are set at server level, in applicationHost.config, which your host controls. A site’s own web.config can switch compression on or off, but it cannot define the schemes or the types, and a httpCompression block in web.config is rejected on most servers with a 500.19 error. Add only this element to the site’s web.config, inside system.webServer. Keep a copy of the file first, because a syntax error stops the site:
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
Ask your host which MIME types the server compresses. A sensible server list covers text, JSON, JavaScript and SVG, and leaves images and archives alone. If a type you need is missing, such as JSON, ask the host to add it at server level.
Step 3: Check the response headers
From a terminal, request a page and ask for gzip. Read the response headers:
curl -sI -H "Accept-Encoding: gzip" https://example.com/ | grep -i "content-encoding\|content-type"
Expected: a content-encoding: gzip line on the HTML response. Check a CSS file too. If the header is missing, the MIME type is not in the list, the file is smaller than the minimum size, or the compression feature is not installed.
Step 4: Check the app does not compress twice
An ASP.NET Core app can compress its own responses with its built-in middleware. If both the app and IIS compress the same response, the browser receives a broken page. Check the app’s startup code for UseResponseCompression. If the app already compresses, leave IIS dynamic compression off for those types, and keep static compression on for files the app does not generate.
The test is simple: load the page in a browser and check that its styles and scripts load. A page with no styles and a blank layout is usually a double compression problem.
Step 5: Measure the result
Run a speed test on the same page before and after the change, from the same location. Look at the transfer size of the HTML, CSS and JavaScript in the browser’s network panel. A text file that drops by most of its size shows compression is working. The total load time should also fall for visitors on slow connections.
Common mistakes
- Compressing images. JPEG and PNG are already compressed, and the work wastes CPU.
- Compressing twice. The app and IIS both compress, and the page breaks.
- Forgetting the feature role. The web.config setting does nothing without the compression service installed.
- Breaking web.config. Keep a copy, and test the site right after each edit.
- Putting scheme or type settings in web.config. They belong to the server, and the file is rejected with a 500.19.
Frequently asked questions
Does compression slow the server down?
Dynamic compression uses CPU on each request. Static compression is cheap, because IIS caches the result. Compress text and leave images alone, and the cost is small.
Why do I see the page uncompressed in one browser?
The browser may not send the gzip header, or a proxy in front of IIS removed it. Test with curl as in Step 3.
Is Brotli supported?
Depends on the IIS version and the modules installed. Gzip is supported on every plan, so start with it.
Does compression help SEO?
Indirectly. A faster page helps the experience measures search engines use, and compression is one of the easiest speed gains.
HTTP compression sends text files in a fraction of their size, which makes pages load faster for every visitor. Install the compression features, enable gzip for text types only, and confirm the header with curl. Watch for double compression if the app already compresses its responses. For the speed of the app itself, read how to fix ASP.NET Core 500.19 configuration error on IIS if the site will not start after an edit.