Most of the websites today use client side scripts, styles and images. When browser requests a webpage, it has to make n number of HTTP requests to get each of these resources. Caching, combining, compressing are few techniques we use to improve the performance of such websites. In this blog I will concentrate on caching images using IIS settings.
Most browsers today inspect the header in the incoming response and do certain actions based on these header values. One such header is expires. The value of this header is usually a datetime. This tells the browser that it is safe for the browser to store this resource on the client side until that date. Hence, next time the requests will not be sent to the server but instead the resource will be picked up from the temporary cache on the client side.
There are two ways to achieve this. One is either by writing your own HttpHandler or other is setting IIS server settings for your website. As seen in the image below, open your IIS manager and navigate to the website folder that you want to cache. Click on the "HTTP Response Headers" icon in IIS group.
Click "Set Common Headers" on the top right side and set the expiry date in the popup window as shown in the image below.
To improve the performance the tools such as yslow suggest that we put a far-future date on the expiry. Sometimes may be in the range of 10 years. The problem with this approach is that if you change the javascript or css file, the client will still be using the old file since the expiry is set far in the future. However, if you change the filename, this problem will not occur as a new cache entry will be created for this new file.
This feature improves the peformance of your website considerably. Cached files dont travel over the wire and no extra HTTP requests are made.
Most browsers today inspect the header in the incoming response and do certain actions based on these header values. One such header is expires. The value of this header is usually a datetime. This tells the browser that it is safe for the browser to store this resource on the client side until that date. Hence, next time the requests will not be sent to the server but instead the resource will be picked up from the temporary cache on the client side.
There are two ways to achieve this. One is either by writing your own HttpHandler or other is setting IIS server settings for your website. As seen in the image below, open your IIS manager and navigate to the website folder that you want to cache. Click on the "HTTP Response Headers" icon in IIS group.
Click "Set Common Headers" on the top right side and set the expiry date in the popup window as shown in the image below.
To improve the performance the tools such as yslow suggest that we put a far-future date on the expiry. Sometimes may be in the range of 10 years. The problem with this approach is that if you change the javascript or css file, the client will still be using the old file since the expiry is set far in the future. However, if you change the filename, this problem will not occur as a new cache entry will be created for this new file.
This feature improves the peformance of your website considerably. Cached files dont travel over the wire and no extra HTTP requests are made.