IIS Modification
Caching and Compression within IIS
Two common and easy ways to increase website performance is to use caching and compression to minimise the amount of bandwidth consumed.
To make sure that the browser caches correctly the Vary http header is used. The header is used by both the browser and servers in-between (such as ISPs) to determine if content is current. For instance, if the Vary header is User-Agent, ISPs will know that content may change depending on a device's User-Agent, so it should give cached content to a device with a new User-Agent. This practice is recommended by Google as it helps with their indexing.
However, when both compression and caching are used in IIS the compression module overwrites the entire Vary header with 'Accept-Encoding', removing all of the intelligence that could previously be applied to a cache. This effectively gives IIS users a choice of compression or caching.
Fixing the Vary Header
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.
51Degrees, together with Erez Benari at Microsoft, has developed two native modules for IIS which restore data stripped from the Vary header. Builds and source code for the modules can be found on our Codeplex page .
These modules work by intercepting the Vary header in the IIS pipeline before compression has occurred, and then putting it back after compression has finished. Two modules are required for this as this is the only way in IIS to do something both before and after compression.
- Before beginning installation check whether your server is 32 or 64 bit. Most servers are 64 bit. You should use the specific DLLs for your system's bitness.
- Navigate to '%windir%\System32\inetsrv'. Copy the DDLs straight into this folder.
- Open IIS in administrator mode. From the root server pane navigate to modules.
- You should see a list of native and managed modules currently installed on the server. On the right hand side is the Action Pane. Click 'Configure Native Modules' to add the modules.
- This should open a dialog box pictured below. If you do not see the register button, close IIS Manager and open it again in administrator mode.
- Click Register. You will be prompted for a name and path to the DLL. The name can be anything, but it should be something you will recognise later. This article uses 'CompressionPreProcessor' and 'CompressionPostProcessor'. The path is the path to the DLLs copied into '%windir%\System32\inetsrv' earlier. Both DLLs will need to be registered.
- Click OK (ensuring that both modules are checked to show they're enabled).
- Now click on 'View Ordered List', also in the action pane. The order is important, we want the CompressionPreProcessor module just before compression, and CompressionPostProcessor just after compression. This way interferes with the IIS pipeline as little as possible. Use the blue up and down arrows on the right to move both modules into position. with CompressionPreProcessor just below the Compression and CompressionPostProcessor just above, as pictured below.
- You should now see webpages from this server using the Vary header as originally intended.
How it Works
The preprocess module saves the contents of the Vary header into a temporary header (named fod_vary_store). This is then read and placed back into the Vary header by the post process module. The temporary header is deleted. The post process also appends the header values left by the compression process. This ensures that devices which don't support compression aren't served compressed content from a cache.