我在装有Microsoft IIS 8.5的Windows Server上有一个网站,我想使用“利用浏览器缓存”,但是我只有以下.htaccess代码:
<IfModule mod_expires.c>
ExpiresActive On
# Images
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
# Video
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"
# CSS, JavaScript
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
# Others
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>
有人可以帮助我将此代码转换为Web.config代码吗?
P.S .:我无法在服务器中使用IIS实用程序,该实用程序会自动转换.htaccess代码。
答案 0 :(得分:1)
我不确定使用web.config进行客户端缓存的粒度如何,您可以设置一个总括数字:
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
</system.webServer>
如果要对其进行细化,则可以停止对某些文件进行缓存:
<configuration>
<location path="path/to/filename.type">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
如果这对您有用,您也可以使用服务器端输出缓存,例如:
<caching>
<profiles>
<add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="02:00:00" />
<add extension=".woff2" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" />
<add extension=".woff" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" />
<add extension=".svg" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="23:59:59" />
<add extension=".js" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="02:00:00" />
<add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="00:10:00" />
<add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="23:59:59" />
</profiles>
</caching>
不确定是否有帮助!