ASP.NET和YSlow的优化 [英] ASP.NET and YSlow optimization
问题描述
我运行在IIS防爆preSS在我小的ASP.NET Web项目运行一个YSlow的性能测试。我左后卫两个项目,我认为需要优化。
1。添加Expires头
我需要设置到期日期我的favicon.ico。我怎样才能做到这一点?
2。催芽缓存
当我看到在统计的标签,我注意到,我的HTML不被缓存。我怎么可以缓存HTML,所以6,7K没有下载第二次?为什么我的图标在底漆缓存requsted?
图标
添加到您的web.config文件:
<结构>
<位置路径=favicon.ico的>
< system.webServer>
< staticContent>
&所述; clientCache cacheControlMode =UseMaxAgecacheControlMaxAge =90.00:00:00/>
< / staticContent>
< /system.webServer>
< /地点>
< /结构>
块引用>HTML缓存
浏览器缓存基于服务器响应的响应头的页面。
您应该只问一个浏览器缓存页面,如果该页面内容将不会为给定时间内改变和用户将在一定时期内访问此页面。您的设置使用类似的高速缓存头:
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(新时间跨度(1,0,0));我建议你看一看的 W3C HTTP缓存规格有关浏览器缓存一个完整的概述。
另外,如果你使用缓存,一些浏览器会询问你的服务器如果该文件是从最后一次修改他们得到他们(的如果-Modified-Since的头)。如果该文件没有改变,你可以用 304状态响应$ C $ç。
I'm running a YSlow performance test on my small ASP.NET web project running in an IIS Express. I'm left back with two items that I think needs optimization.
1. Add Expires headers
I need to set expire date on my favicon.ico. How can I do this?
2. Primed cache
When I look in the statistics tab, I notice that my HTML is not cached. How can I cache the HTML, so the 6,7K is not downloaded the second time? Why is my favicon requsted in primed cache?
解决方案favicon:
Add this to your web.config file:
<configuration> <location path="favicon.ico"> <system.webServer> <staticContent> <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" /> </staticContent> </system.webServer> </location> </configuration>
Html Cache:
The browser caches a page based on the response headers of the server response. You should only ask a browser to cache a page if the page contents will not change for a given period of time and an user will revisit this page in the given period.
You an set an cache header using something like:
Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));
I recommend that you take a look at the W3C http cache specifications for a full overview about browser cache.
Also, if you use cache, some browsers will ask your server if the file was modified since the last time they get them (the "If-Modified-Since" header). If the file was not changed, you can respond with the 304 status code.
这篇关于ASP.NET和YSlow的优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!