.htaccess - 如何将此 .htaccess 杠杆浏览器缓存代码转换为 web.config 杠杆浏览器缓存代码?
问题描述
我在带有 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 代码。
解决方案
我不确定您是否可以使用 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>
不知道这是否有帮助!
推荐阅读
- arrays - F#:n 个空列表的数组
- python - 在虚拟框中的 Ubuntu 18.04 中的共享目录中创建虚拟环境失败
- spring-boot - 如何使用 Spring-kafka @KafkaListener 从来自 kafka 的消息中读取特定数据?
- javascript - 有没有办法在给定的href链接上重定向我的页面而不加载
- spartacus-storefront - 如何使用自定义 API 连接 Spartacus
- android - 在android中禁用电源按钮不起作用
- android - 如何清除初始化“com.intellij.openapi.vfs.newvfs.ManagingFS”的致命错误
- angular - 如何使用角度动画顺序滑出?
- java - 使用 keysValues 创建 yml
- android - 实施路线时,原始标记不会不可见