我如何将此 .htaccess 杠杆浏览器缓存代码转换为 web.config 杠杆浏览器缓存代码?
How can i convert this .htaccess leverage browser caching code into web.config leverage browser caching code?
我在装有 Microsoft IIS 8.5 的 Windows 服务器上有一个网站,我想使用 "Leverage browser caching" 但我只有这个 .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.: 我无法在我的服务器中使用自动转换 .htaccess 代码的 IIS 实用程序。
我不确定你可以这样 fine-grained 对于客户端缓存 web.config,你可以设置一个总图:
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
</system.webServer>
如果您想 fine-grain 它,您可以停止缓存某些文件:
<configuration>
<location path="path/to/filename.type">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
如果这对您有用,您也可以使用 server-side 输出缓存,如下所示:
<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>
不确定是否有帮助!
我在装有 Microsoft IIS 8.5 的 Windows 服务器上有一个网站,我想使用 "Leverage browser caching" 但我只有这个 .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.: 我无法在我的服务器中使用自动转换 .htaccess 代码的 IIS 实用程序。
我不确定你可以这样 fine-grained 对于客户端缓存 web.config,你可以设置一个总图:
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
</system.webServer>
如果您想 fine-grain 它,您可以停止缓存某些文件:
<configuration>
<location path="path/to/filename.type">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
如果这对您有用,您也可以使用 server-side 输出缓存,如下所示:
<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>
不确定是否有帮助!