The NoteBook of EricKong

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            611 Posts :: 1 Stories :: 190 Comments :: 0 Trackbacks

          I’ve been tweaking the performance of BlogEngine.NEXT today using my favorite tool: YSlow for FireBug. One of the things YSlow checks for is the expires HTTP header for static content such as images, script files and style sheets. Since BlogEngine.NET has always used custom HTTP handlers for serving scripts and stylesheets, only the static images have been a problem.

          The problem

          The problem is that with images on hosted environments on IIS 6, it’s impossible to control the serving of them without redirecting them through an HTTP handler. That’s not a good idea for several reasons:

          • It adds unnecessary overhead by going through the ASP.NET ISAPI
          • You need to add custom code to handle the requests
          • You need to change the URL from .gif to .gif.axd or similar

          Here is what YSlow finds on my website that needs the expires header set to a far future date:


          As you can see, it is all my static images that lacks the expires header.

          The solution

          If you run IIS 6 there is no good way of adding an expires header to images unless you have control over the IIS. If your site is hosted then you probably have no control at all. If you are using IIS 7 however, you can very easily add the header in your web.config’s system.webServer section like so:

          <staticContent>
           <clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
          </staticContent>

          What happens is that all static content will now have an expires HTTP header set to the year 2020. Static content means anything that isn’t served through the ASP.NET engine such as images, script files and styles sheets. This is one of the very easy tricks that will increase the performance of your site as well as your YSlow score.

          posted on 2010-07-21 10:23 Eric_jiang 閱讀(1175) 評(píng)論(0)  編輯  收藏 所屬分類: HTML
          主站蜘蛛池模板: 陈巴尔虎旗| 凭祥市| 革吉县| 博爱县| 堆龙德庆县| 无极县| 大埔区| 铁力市| 宝丰县| 曲水县| 兖州市| 德保县| 泸西县| 边坝县| 道孚县| 阿勒泰市| 林口县| 根河市| 浦东新区| 静安区| 德安县| SHOW| 琼结县| 枣庄市| 巴林右旗| 云林县| 弥勒县| 和顺县| 都江堰市| 安义县| 芦山县| 原平市| 南乐县| 韩城市| 绥宁县| 永兴县| 九龙坡区| 贵南县| 灵台县| 山阴县| 隆化县|