zoukankan      html  css  js  c++  java
  • 一次我们网站的web性能优化

    1.Google的Web优化最佳实践

        利用 PageSpeed工具 对我们红酒世界网进行检测时,发现了下面的几个问题

         1.Leverage browser caching

        1.1.通过web.config设置静态文件缓存

               <system.webServer>

               <staticContent>

            <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
           </staticContent>

                  </system.webServer>

               这里设置了1天的静态文件缓存。

                1.2.利用代码处理动态文件缓存 

         在需要进行动态文件缓存的时候调用,也可以写在basepage下, 关于http客户端缓存可以参考:http://www.cnblogs.com/luminji/archive/2011/09/14/2174751.html

     private void SetBuffer()
            {
                if (HttpContext.Current != null)
                {
    
                        var modifiedTime = DateTime.MinValue;
                        if (Request.Headers["If-Modified-Since"] != null && DateTime.TryParse(Request.Headers["If-Modified-Since"], out modifiedTime))
                        {
                            if (TimeSpan.FromTicks(DateTime.Now.Ticks - modifiedTime.Ticks).TotalSeconds < secondsTime)
                            {
                                Response.ClearContent();
                                Response.StatusCode = (int)System.Net.HttpStatusCode.NotModified;
                                Response.SuppressContent = true;
                                return;
                            }
                        }
                        else
                        {
                            //设置客户端缓存状态
                            SetClientCaching(Response, DateTime.Now);
                        }
                }
    }
     /// 设置客户端缓存状态
            /// </summary>
            /// <param name="response"></param>
            /// <param name="lastModified"></param>
            private void SetClientCaching(HttpResponse response, DateTime lastModified)
            {
                response.Cache.SetETag(lastModified.Ticks.ToString());
                response.Cache.SetLastModified(lastModified);
                //public 以指定响应能由客户端和共享(代理)缓存进行缓存。
                response.Cache.SetCacheability(HttpCacheability.Public);
                //是允许文档在被视为陈旧之前存在的最长绝对时间。
                response.Cache.SetMaxAge(new TimeSpan(0, 0, 0, 30));
                //将缓存过期从绝对时间设置为可调时间
                response.Cache.SetSlidingExpiration(true);
            }
    

      

  • 相关阅读:
    mySQL部分疑问和小结(orale)
    Java技术中的三大特性
    Java调用DB的存储过程
    Android Http异步请求,Callback
    android Handler的使用(一)
    Android之ContextMenu的使用方法以及与OptionMenu的区别(转)
    git 把文件从 版本管理中移除 andorid版本
    在GIT 中增加忽略文件夹与文件
    玩转Android---组件篇---Intent(意图)
    Android Activity和Intent机制学习笔记
  • 原文地址:https://www.cnblogs.com/lian9527/p/3571324.html
Copyright © 2011-2022 走看看