I have a MVC3 site running on IIS 7.5 that has compression enabled.
The GZip compression is working on all pages of the site except for a few pages where I manually change the content type to application/xhtml+xml (this is necessary for various reasons) in the controller (Response.ContentType = "application/xhtml+xml";).
What about this content type would cause GZip not to work, and is there any way around that?
application/xhtml+xmlis not one of the built in mime types that IIS compression knows to compress. You must enable compression for this mime-type explicitly.I’ll assume you want the compression to be enabled whether it’s a static file or dynamically generated. To do this you must add the mime-type to the machine level config’s
system.webServer/httpCompressionstaticTypesanddynamicTypessections. One of the simpler ways to do this with a deployment script is to just useappcmd.exelike so:Adding support for compressing static content
Adding support for compressing dynamic content
Obviously you can use this same approach for any other content types you might want compressed.