zoukankan      html  css  js  c++  java
  • 只加载一个css文件(转载)

    转自:http://www.cnblogs.com/easygame/archive/2010/11/20/1882543.html

    (1).指定一个通用的Web服务器端处理CSS请求的程序,以ASP.NET 为例,我们可以在根目录下创建一个HttpHandler用来接收所有页面的CSS请求。

    public class Handler : IHttpHandler {
    public void ProcessRequest(HttpContext context)
    {
    context.Response.ContentType
    = "text/css";
    }

    public bool IsReusable {
    get {
    return false;
    }
    }
    }

        (2).根据现有页面加载的所有CSS,把单独的CSS路径信息作为HttpHandler处理程序的参数传入。即多个<link>标签转化为一个<link>标签,而原有的请求信息转化为参数形式。

    <link type="text/css" rel="Stylesheet" href="styles/common.css"/>
    <link type="text/css" rel="Stylesheet" href="styles/skin1/skin1.css"/>

       转化后:

    <link type="text/css" rel="Stylesheet" href="Handler.ashx?common=/styles/common.css&skin1=/styles/skin1/skin1.css" />

        (3).在HttpHandler处理程序中根据参数信息,读取不同的CSS文件内容并发送到输出流。上述代码为了阐述问题只包含必要的部分,如果在上一步中对参数的形式进行了格式化,在当前代码中提取参数时要做相应的处理。

    public class Handler : IHttpHandler {
    public void ProcessRequest(HttpContext context)
    {
    context.Response.ContentType
    = "text/css";
    for (int i = 0; i < context.Request.QueryString.Count; i++)
    {
    string path =context.Request.MapPath(context.Request.ApplicationPath+context.Request.QueryString[i]);
    using (TextReader tr = new StreamReader(path))
    {
    context.Response.Write(tr.ReadToEnd()
    +"\n");
    }
    }
    }
    public bool IsReusable {
    get {
    return false;
    }
    }
    }

    2.如何让网站根据不同的浏览器(如IE6)的加载不同的CSS文件?

      开发或改版网站时,IE浏览器由于个别版本不遵循标准,并且有数量众多臭名昭著的BUG,给我们带来了很多困难。为了兼容IE,我们不得不经常用条件注释和CSS hack处理它。我们理想的方式是先针对标准的浏览器开发,如FireFox。然后在IE下测试并达到兼容的目标。通过在后台控制加载的方式,我们不需要条件注释,不需要对CSS添加无意义的属性或hack来兼容IE。个人认为,为IE提供另一套CSS或部分独立的CSS所需要的时间是少于通过CSS hack或牺牲IE不支持的CSS特性进行兼容的时间的。

    public class Handler : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
    context.Response.ContentType
    = "text/css";
    for (int i = 0; i < context.Request.QueryString.Count; i++)
    {
    string path =context.Request.MapPath(context.Request.ApplicationPath+context.Request.QueryString[i]);
    if (context.Request.Browser.Browser == "IE" && context.Request.Browser.Version == "6.0")
    {
    path
    = path.Replace(".css", "-ie6.css");
    }
    using (TextReader tr = new StreamReader(path))
    {
    context.Response.Write(tr.ReadToEnd()
    +"\n");
    }
    }
    }

    public bool IsReusable {
    get {
    return false;
    }
    }
    }
  • 相关阅读:
    How To Install a 2 Finger Gripper on ABB Robots
    Guide: How to Set Up I/O on an ABB Robot with an IRC5 Controller
    SIGVerse
    unity与ROS SIGVerse 仿真
    论文阅读:Automated acquisition of structured, semantic models of manipulation activities from human VR demonstration
    Python2.7+ROS环境:AttributeError:‘module’ has no attribute ‘CALIB_HAND_EYE_TSAI
    Qt音视频开发39-人脸识别在线版
    Qt音视频开发38-USB摄像头解码linux方案
    Qt音视频开发37-USB摄像头解码ffmpeg方案
    由浅入深讲述MVVM
  • 原文地址:https://www.cnblogs.com/johnwonder/p/1887073.html
Copyright © 2011-2022 走看看