No expires header
I have the report from YSlow:
(no expires) http://static3.scirra.net/avatars/128/40cfdcbd1b1ec1842e199c97c4b85a4a.png
(And a lot more similar). In my web.config though, I have:
<system.webServer>
<staticContent>
<clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
</staticContent>
<caching>
<profiles>
<add extension=".ashx" policy="CacheForTimePeriod" ker开发者_运维知识库nelCachePolicy="DontCache" duration="01:00:00" />
<add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" location="Any" />
</profiles>
</caching>
<rewrite>
<rules>
<rule name="Avatar">
<match url="avatars/([0-9]+)/(.*).png" />
<action type="Rewrite" url="gravatar.ashx?hash={R:2}&size={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
Should this not be adding the expires header correctly? My objectives are:
- Gravatar.ashx fetches image from Gravatar server
- Server caches result for 1 hour (similar to SO)
- Expires header is added so client doesn't keep fetching it from my server
In IIS you can define HTTP Headers.
Within IIS click your images folder. Then click HTTP Response Headers. Then Set Common Headers...
From here you can check Expire Web Content and after how much time you choose. You can also do this for JS and CSS. Be careful which files you apply this too. Also if you set a very far out expiration and you plan to change these files you could cause problems for your site.
If you have 1 month expiration on a JS file and then you change it while using the same name then when a user visits your site they will see the content has not expired and will not request the changed file from the web server. You can cope with this by setting modest expiration times while you think the content is subject to change or you can apply version numbers to your javascript and CSS files.
精彩评论