zoukankan      html  css  js  c++  java
  • 页面优化小记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地址加上一个时间戳即可

  • 相关阅读:
    自定义checkbox样式
    自定义select样式
    jsonp
    I/O复用 poll简介
    DOS和DDOS攻击
    TCP状态转换图解析
    Makefile入门
    I/O复用select 使用简介
    替换文本内容
    share memory
  • 原文地址:https://www.cnblogs.com/madboy/p/2693275.html
Copyright © 2011-2022 走看看