0

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.

Community
  • 1
  • 1
Mahdi Ghiasi
  • 14,873
  • 19
  • 71
  • 119

2 Answers2

1

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.

Community
  • 1
  • 1
Nick Bork
  • 4,831
  • 1
  • 24
  • 25
  • I haven't access to the IIS, since my hosting plan is a shared hosting. Isn't there any way to do it with Web.config or plesk? – Mahdi Ghiasi Jan 16 '12 at 21:30
  • IIS 6 does not have any configuration settings to enable you to do it. You can try a support ticket with your hosting provider to see if they can make the change for you. Even making a HTTP Handeler would require some changes from your hosting provider. IIS6 doesn't use ASP.NET to process static files so you would need your hosting provider to enable a wild card mapping in order for the HTTP Handeler to work. You can see this thread to see the issues I've described above: http://stackoverflow.com/questions/1927770/setting-far-future-expires-header-in-code-asp-net – Nick Bork Jan 16 '12 at 23:29
  • The moral of the story is either upgrade to IIS7 or open a support ticket to either enable the expires header or add a wild card mapping to enable you to use an IHTTPHandeler – Nick Bork Jan 16 '12 at 23:32
  • They are using "ionic's isapi rewrite filter" to enable wild card mapping, how should I do? (I have updated my question) – Mahdi Ghiasi Jan 17 '12 at 04:32
1

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

Nick Bork
  • 4,831
  • 1
  • 24
  • 25