样式表:1个大的或者几个大的或者几个小的?

时间:2022-08-04 09:26:44

I am building an ASP.NET website with several style sheets.

我正在构建一个包含多个样式表的ASP.NET网站。

Each style sheet is focused on a different page / pages. Is it better performance-wise to have all the styles merged into 1 or will bundling solve this anyway?

每个样式表都集中在不同的页面/页面上。将所有样式合并为1还是将捆绑解决此问题更好的性能?

Personally, I find several style sheets handier because it gives you a better overview of what rules are available.

就个人而言,我发现有几种样式表比较方便,因为它可以让您更好地了解可用的规则。

2 个解决方案

#1


1  

Instead I would suggest you to merge the stylesheets in a single file and comment out the blocks accordingly, because your approach seems unfriendly, also, it will be a huge performance hit, as stylesheets will be requested everytime a user navigates a new page, thus increasing in http requests.

相反,我建议你将样式表合并到一个文件中并相应地注释掉块,因为你的方法看起来不友好,而且,每次用户导航新页面时都会请求样式表,因此会产生巨大的性能损失,因此增加http请求。

Also some of the core styles will be repeated on every page like resets, font sizes and families etc, so you must be having 2 on each page, 1 which will handle the base styles and other which are applied per page, instead merge them in one.

还有一些核心样式将在每个页面上重复,如重置,字体大小和族等,所以你必须在每个页面上有2个,1个将处理基本样式和其他每页应用,而不是合并它们一。

Particularly I follow this convention..

特别是我遵循这个惯例..

/* Core Styles */

* {
   margin: 0;
   padding: 0;
}

html {
   height: 100%;
}

body {
   min-height: 100%;
   /* Other stuffs */
}

/* Core Styles Ends */

/* Header Styles */

/* Header styles here */

/* Header Styles ends */

/* Home page styles starts */

/* Home page styles ends */

This way you can also use the styles across the pages, you don't need to repeat some on every page, for example font color, font size, h1-h6 styles etc

这样你也可以在页面中使用样式,你不需要在每个页面上重复一些,例如字体颜色,字体大小,h1-h6样式等

#2


2  

You mentioned bundling, so I'm assuming that you're talking about the bundling function present in ASP.NET Optimization.

你提到了捆绑,所以我假设你在谈论ASP.NET优化中存在的捆绑功能。

If so, then that's the whole point of bundles: you work with multiple separate files / modules in development, and have them merged / minimized into a single file in production.

如果是这样,那么这就是捆绑包的重点:您在开发中使用多个单独的文件/模块,并将它们合并/最小化为生产中的单个文件。

Just make sure that your bundles are defined / categorized properly, and you shouldn't have to think about having "too many" multiple files to work with, as they get combined into singular files when it really matters.

只需确保您的捆绑包已正确定义/分类,您就不必考虑使用“太多”多个文件,因为它们在真正重要时会合并为单个文件。

#1


1  

Instead I would suggest you to merge the stylesheets in a single file and comment out the blocks accordingly, because your approach seems unfriendly, also, it will be a huge performance hit, as stylesheets will be requested everytime a user navigates a new page, thus increasing in http requests.

相反,我建议你将样式表合并到一个文件中并相应地注释掉块,因为你的方法看起来不友好,而且,每次用户导航新页面时都会请求样式表,因此会产生巨大的性能损失,因此增加http请求。

Also some of the core styles will be repeated on every page like resets, font sizes and families etc, so you must be having 2 on each page, 1 which will handle the base styles and other which are applied per page, instead merge them in one.

还有一些核心样式将在每个页面上重复,如重置,字体大小和族等,所以你必须在每个页面上有2个,1个将处理基本样式和其他每页应用,而不是合并它们一。

Particularly I follow this convention..

特别是我遵循这个惯例..

/* Core Styles */

* {
   margin: 0;
   padding: 0;
}

html {
   height: 100%;
}

body {
   min-height: 100%;
   /* Other stuffs */
}

/* Core Styles Ends */

/* Header Styles */

/* Header styles here */

/* Header Styles ends */

/* Home page styles starts */

/* Home page styles ends */

This way you can also use the styles across the pages, you don't need to repeat some on every page, for example font color, font size, h1-h6 styles etc

这样你也可以在页面中使用样式,你不需要在每个页面上重复一些,例如字体颜色,字体大小,h1-h6样式等

#2


2  

You mentioned bundling, so I'm assuming that you're talking about the bundling function present in ASP.NET Optimization.

你提到了捆绑,所以我假设你在谈论ASP.NET优化中存在的捆绑功能。

If so, then that's the whole point of bundles: you work with multiple separate files / modules in development, and have them merged / minimized into a single file in production.

如果是这样,那么这就是捆绑包的重点:您在开发中使用多个单独的文件/模块,并将它们合并/最小化为生产中的单个文件。

Just make sure that your bundles are defined / categorized properly, and you shouldn't have to think about having "too many" multiple files to work with, as they get combined into singular files when it really matters.

只需确保您的捆绑包已正确定义/分类,您就不必考虑使用“太多”多个文件,因为它们在真正重要时会合并为单个文件。