Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a page opt out of IIS 7 compression?

My pages are automatically being compressed by IIS7 with GZIP.

That is great... but, for one particular page, I need to stream it to the user, using Response.Flush() when needed. But when the output is being compressed, the IIS server seems to collect all my output until the page is done before compressing and sending it to the client. That nullifies my attempt to Flush the content out to the user.

Is there a way that I can have this one page opt out of the compression?

One possible option

I've determined that if I manually set the content type to one that does not match the IIS configuration at c:\windows\system32\inetsrv\config\applicationhost.config, then IIS will not compress it. Eg. Response.ContentType = "x-text/html". This works okay with IE8, as it falls back to display the HTML. But Firefox will ask the user what to do with the unknown file type.

This could work, if there was another Mime Type I could use that browsers would accept as HTML, that is not matched in the applicationhost.config. For reference, these are the mime types that will be compressed:

   <add mimeType="text/*" enabled="true" />
   <add mimeType="message/*" enabled="true" />
   <add mimeType="application/x-javascript" enabled="true" />
   <add mimeType="application/atom+xml" enabled="true" />
   <add mimeType="application/xaml+xml" enabled="true" />

Others options?

Are there other options to opt out of compression?

like image 598
Glen Little Avatar asked Apr 20 '10 19:04

Glen Little


People also ask

How do I disable IIS compression?

In Control Panel, click Programs and Features, and then click Turn Windows features on or off. Expand Internet Information Services, expand World Wide Web Services, expand Performance Features, and then select Dynamic Content Compression and/or Static Content Compression. Click OK. Click Close.

How do I enable dynamic content compression in IIS 7?

Select the Internet Information Services (IIS) Manager under Roles > Web Server (IIS). In the IIS Manager, select the desired Site and open the Compression option (Features View). In the Compression window, mark the check box corresponding to the Enable dynamic content compression option.


3 Answers

It may not be possible to disable compression for a certain page, but you can for a directory.

This describes how to disable static compression, but it may work for dynamic compression: (From http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/502ef631-3695-4616-b268-cbe7cf1351ce.mspx?mfr=true)

To disable static compression for only a single directory, first enable global static compression (if it is disabled) and then disable static compression at that directory. For example, to enable static compression for a directory at http://www.contoso.com/Home/StyleSheets, perform the following steps:

  1. Enable global static compression by executing the following command at a command prompt:

adsutil set w3svc/filters/compression/parameters/HcDoStaticCompression true

  1. Disable static compression at this directory by executing the following command at a command prompt:

adsutil set w3svc/1/root/Home/StyleSheets/DoStaticCompression false

like image 134
Nicolas Avatar answered Oct 04 '22 09:10

Nicolas


Not sure I like this but maybe worth mentioning: Disable GZIP compression for IE6 clients

like image 27
MK. Avatar answered Oct 04 '22 10:10

MK.


You could use a custom made compression module, like this one:

HTTP compression of WebResource.axd and pages in ASP.NET

Using such it should be easy to customize which files to include/exclude.

like image 44
asgerhallas Avatar answered Oct 04 '22 08:10

asgerhallas