3

我在基于 IIS 6 的网站上的文件夹中有一些静态图像,我希望尽可能少地下载这些图像(以节省带宽)。我已将内容过期设置为 30 天后过期。我可以在 IIS 中做些什么来尝试最大化浏览器、代理和网关缓存的缓存吗?

比如添加一个Cache-Control头?还要别的吗?

4

2 回答 2

1

http://www.galcho.com/Blog/post/2008/02/27/IIS7-How-to-set-cache-control-for-static-content.aspx

这是一篇博客文章,涵盖以下内容:

  1. 允许覆盖静态内容设置
  2. 使用以下命令设置缓存设置
  3. 在客户端缓存
于 2008-11-13T16:43:43.527 回答
1

这是我对这个问题的回答:静态内容的 http 标头中的“过期”?如何

@ECHO OFF 
REM ---------------------------------------------------------------------------
REM Caching - sets the caching on static files in a web site
REM syntax 
REM     Caching.CMD 1 d:\sites\MySite\WWWRoot\*.CSS
REM 
REM   %1 is the WebSite ID
REM   %2 is the path & Wildcard - for example, d:\sites\MySite\WWWRoot\*.CSS
REM   _adsutil is the path to ADSUtil.VBS
REM ---------------------------------------------------------------------------

SETLOCAL
REM *******
REM SET THIS TO POINT TO adsutil.vbs - TYPICALLY c:\inetpub\adminscripts\adsutil.vbs
REM *******
SET _adsutil=D:\Apps\Scripts\adsutil.vbs

FOR %%i IN (%2) DO (
  ECHO Setting Caching on %%~ni%%~xi
  CSCRIPT %_adsutil% CREATE W3SVC/%1/root/%%~ni%%~xi "IIsWebFile"
  CSCRIPT %_adsutil% SET    W3SVC/%1/root/%%~ni%%~xi/HttpExpires "D, 0x69780"
  ECHO.
)

它将 Web 根目录中每个 CSS 文件的缓存值设置为 5 天,然后像这样运行它:

Caching.CMD 1 \site\wwwroot\*.css
Caching.CMD 1 \site\wwwroot\*.js
Caching.CMD 1 \site\wwwroot\*.html
Caching.CMD 1 \site\wwwroot\*.htm
Caching.CMD 1 \site\wwwroot\*.gif
Caching.CMD 1 \site\wwwroot\*.jpg

有点痛苦,但可行。

顺便说一句 - 要获取 HttpExpires 的值,请在 GUI 中设置值,然后运行

AdsUtil.vbs ENUM W3SVC/1/root/File.txt

获得您需要的实际价值

于 2008-11-13T22:53:35.310 回答