.htaccess asp-classic browser-cache cache-control web-config

asp classic - 我如何将这个.htaccess杠杆浏览器缓存代码转换为web.config杠杆浏览器缓存

发布于 2020-03-27 10:35:47

我在装有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代码吗?

PS:我无法在服务器中使用IIS实用程序来自动转换.htaccess代码。

查看更多

查看更多

提问者
Alessio Puccini
被浏览
121
Ralpharama 2019-07-03 21:35

我不确定使用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>

不确定是否有帮助!