asp.net – 是否可以有条件地包含CSS?

我有一个ascx,里面有一些CSS.这个ascx可能会多次添加页面中.它使用的CSS只需要包含一次.

>是否可以有条件地包含CSS?如果是这样的话?
>这被认为是不好的做法吗?

解决方法

I have an ascx that has some CSS in it… Is this considered bad practice?

是.理想情况下,CSS规则应该在一个单独的静态css文件中定义,该文件只能在主页的标题中加载一次.正文中的CSS不符合标准.

如果您在静态CSS文件上设置了良好的缓存规则,这将显着减少您通过网络传输的数据量,因为不需要为每个页面加载再次加载CSS规则.如果要在呈现某些相关ASCX文件时仅在头中包含此文件,请查看Neil Fenwick’s answer.

更新

无论出于何种原因,尼尔芬威克似乎已经删除了他的答案.希望他不介意我在这里复制它:

Definitely YES,it is possible.

I would recommend looking at a library like 07001 to manage your CSS and JS includes & dependencies.

Good examples for how to include given on ClientDependency codeplex page. Its good practice to organise your CSS and JS dependencies so that you can assert their requirement multiple times,but only emit the dependency in the output once.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....