How do I add Expires Header to a custom file in iis7?
I need to add an expires header to my .les开发者_开发知识库s files in IIS7. Not quite sure how to do it.
If your .less files are all located in the same folder you could specify the httpExpires
attribute for static content with an additional web.config
in this specific folder:
<system.webServer>
<staticContent>
<clientCache
httpExpires="Sun, 29 Mar 2020 00:00:00 GMT"
cacheControlMode="UseExpires" />
</staticContent>
</system.webServer>
Or add the same section in your root web.config
and define the location path for the folder containing the .less files:
<location path="YourLessFilesFolder">
<system.webServer>
<staticContent>
<clientCache
httpExpires="Sun, 29 Mar 2020 00:00:00 GMT"
cacheControlMode="UseExpires" />
</staticContent>
</system.webServer>
</location>
You would also need to add the .less files to the collection of static content types (see). I'm not sure about the MIME type, but you get the idea:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".less" mimeType="text/css" />
</staticContent>
</system.webServer>
Be careful with setting the httpExpires date, I would not use a higher value than one year. You have no possibility to replace the cached files from proxy severs and clients until the expier date is reached. In your example in 20 years!
Use cache validation instead of expiration to be on the save side.
Or use:
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
to cache files for one day.
More Information here.
精彩评论