页面优化小记1

1、缓存

从两个部分入手

1、页面缓存

在页面头部添加

   1: <%@ OutputCache Duration="10" VaryByParam="None" %>

使用了这个OutputCache指令,用来告诉浏览器此页面需要缓存10秒钟。

注:页面加载时,如果调用ajax,则ajax无法缓存,必须自己处理ajax方面的缓存。

2、代码缓存

代码缓存使用HttpRunTime.Cache,使用例子如下

   1: string resul = HttpRuntime.Cache["GetTemplate"];
   2: if(result == null)
   3: {
   4:     result = Db.GetTemplate();
   5:     HttpRuntime.Cache.Add("GetTemplate" + appCID,
   6:                                             result,
   7:                                             null,
   8:                                             DateTime.Now.AddMinutes(5),
   9:                                             TimeSpan.Zero,
  10:                                             System.Web.Caching.CacheItemPriority.Normal,
  11:                                             null);
  12: }
  13: return result;

 

缓存使用资料详见:

细说 ASP.NET Cache 及其高级用法

细说 ASP.NET控制HTTP缓存

 

2、Ajax

ajax使用要遵循获取数据用get,发送数据用post的原则。

get方法会自动缓存,而post从不缓存,如果想让get方式不产生缓存,则在url地址加上一个时间戳即可

posted @ 2012-09-19 10:21  多啦A梦的弟弟  阅读(161)  评论(0编辑  收藏  举报