51degrees logo

Using the Vary Header with Compression in IIS

Products Team

7/17/2013 2:38 AM


Eraz Benari and his team at Microsoft have now released an official fix for this problem. You can download the patch here. If you have already installed our previous fix, it is advised to uninstall it completely and revert to the official solution.

Download Official Patch

Two common and easy ways to increase website performance is to use caching and compression to ensure a minimal amount of bandwidth is consumed.

Google's guidelines on caching is to use the Vary http header to specify which conditions the page may change. For instance, if the Vary header was 'User-Agent' then the Google indexer and your ISP will know that the webpage may change depending on device useragent, useful for mobile optimised pages.

This header is easy to set in any .NET based web site using the code Response.Cache.Headers.UserAgent = true. However when Dynamic Compression is enabled in IIS 7 or 8 the Vary header is removed after .NET managed code has completed execution. This prevents IIS based web sites from using Dynamic Compression and respecting Google's requirements. Dynamic Compression should be enabled for best practice performance reasons, particularly when dealing with mobile phones typically using low bandwidth connections.

A further complication is that any downstream public caching will also fail if Dynamic Compression is enabled. The problem was first reported last year, and is only now being recognised as a major issue for IIS based web sites as Google are now becoming more strict and mobile SEO more relevant to web site owners. The following page contains details of Google's recommendations.

Fortunately, with the help of Erez Benari at Microsoft, 51Degrees.mobi has made two IIS modules that combine the Vary headers of the website before and after compression. For installation and download instructions, click here.