ReviewHostingASP.NET – By using a customized expiry header, your web components like images, static files, CSS, JavaScript skipped unnecessary HTTP request when the same user reload the page for the second time. It reduces the bandwidth needed and definitely help in serving the speed of ASP.NET website faster. By default, static content served from the web server does not have expiry dates. We can instruct the browser on how to cache the content, and for how long.  If you set the expiration to a future date, the browser will not make a request to the server but instead the static content will be served from the browser’s internal cache.

In the web.config, there is a section where you can control these settings:

You can change these settings to cache all the static content requested from the server, for instance cache it maximum for a year. Pay attention that the expiration is a sliding expiration, which means the content will be server from the cache from today up to a year.

Now, the web server will automatically add this header to the static files. What would happen if you make a change to your CSS/JavaScript file?  With the above settings in place, the browser will not serve those changes for the entire year. One way to tackle this issue is to force the browser to refresh the cache. You may also change the URL (i.e add query string, fingerprint/timestamp) to treat the page as a new URL, so the cache get refreshed.



ASP.NET Web Performance Optimization: Customize Header Expiry