I have a shared hosting account with ASP.NET , Windows Server 2003 , IIS6 and Plesk 8.6 control panel.
How can I set the expiry date of CSS, JS and images? Is it possible in shared hosting? With web.config
or other file? How?
Currently gtmetrix.com says that the expiry date of some files are not set.
EDIT : There is an almost same question for IIS7. will the method in this question also works for IIS6?
EDIT 2 : My hosting provider uses ionic's isapi rewrite filter
for wild card mapping.
2
Answers
This answer was for the original question of “How to set the expires header in IIS 6”, after posting the answer and some discussion the topic was changed to be about how to use Ionics ISAPI Rewrite module
Three things come to mind:
1.) Based on this article, you could go in to IIS and enable content expiration or set a custom header for files requested from a specific folder, such as /images/ or /css/
https://stackoverflow.com/a/1271082/768804
and
http://blogs.microsoft.co.il/blogs/yevgenif/archive/2009/02/11/web-performance-expiration-data-iis-6-0.aspx
2.) Use a script to loop through the files in your site and add headers to IIS on a one-by-one basis:
https://stackoverflow.com/a/288652/768804
3.) Create a custom HTTP handeler that will do it for you, but doing this is dirty and should be avoided. It would require IIS to handel static file requests which will reduce performance and increase response time and CPU/Memory load.
Ionics Isapi help documentation can be found here:
http://iirf.codeplex.com/documentation
Depending on the version of the filter there is different documentation. The filter has a function called RewriteHeader which will allow you to set the header.
You’ll need to create a RewriteCondition that parses the URL for .js, .css, .jpg, .jpeg, .png, .gif, etc and then RewriteHeader with a new expires header..
You can review the following page for more information on how to set an expires header, mainly see 14.9.3 and 14.21.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
As for how to calculate the value to set in the header, you may want to post that in the Discussion section of the CodePlex site for the project:
http://iirf.codeplex.com/discussions