每页一个样式表! [英] One Stylesheet Per Page!

查看:104
本文介绍了每页一个样式表!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个新设计的想法.但基本上,它是最后一个设计的扩展版本(?),并且最后一个设计的CSS文件长2096行! (那是普通的/正常的吗?)无论如何,我想起的这个新设计非常独特,因为我以前从未在其他地方看到过.

I have an idea for a new design. But basically, it's an extended(?) version of the last design, and the last design's CSS file was 2096 lines long! (Is that common/normal?) Anyway, this new design I have in mind is pretty unique I guess since I have not seen it elsewhere before.

它将有很多隐藏的东西,只有当被某些东西激活时才可见.每个页面都有相同的布局",但是,取决于您所在的页面,以及取决于单击或悬停的内容,布局将发生巨大变化.

It will have lots of hidden things that only become visible when activated by something. Each page has the same "layout", however, depending on the page you're on, and depending on what was clicked, or hovered over, the layout will drastically change.

每页有一个样式表是否是好的做法"?

Would it be "good practice" to have 1 stylesheet for each page?

我并没有看到任何负面影响,但我确实认为这将有助于维护它,甚至可能会加快网站速度,因为每个页面都不会加载比该页面更多的CSS文件. 2000行长.

I don't really see any down-side to this, but I do think it will help maintain it, and maybe even speed up the site a little, since each page won't be loading a CSS file that's more than 2000 lines long.

如果我只为这个新站点保留一个样式表,那么我敢打赌,我的钱将至少有8000行.进行简单的查找与查找在现有样式表中进行替换已经是一场噩梦.

If I keep just the single stylesheet for this new site, I'd bet all my money that it'll be atleast 8000 lines long. Doing a simple Find & Replace in the existing stylesheet is a nightmare already.

推荐答案

有几种查看方式.

如果将它们全部组合为一个,则CSS文件将仅下载一次.然后它将被缓存,因此后续的页面请求将不会下载CSS文件.这将使初始页面加载速度变慢,而其余页面加载速度变快.

If you combine all of them into one, the CSS file will only be downloaded once. It will then be cached, so subsequent page request won't download the CSS file. This will make the initial page load slower, but the rest of the pages load faster.

第二种解决方案是使用主+个人页面样式表.主页面用于页面之间的通用,另一页面用于页面特定的CSS.这种方法在获取页面时增加了一个额外的请求,但允许您将页面特定的CSS分开.您还可以在特定页面的头部包含特定于页面的CSS.这样可以减少每页加载的请求数.

The second solution is to use a main + individual page stylesheet. Use the main one for things that are common between the pages and another one for page specific CSS. This approach adds an extra request when getting the page, but allows you to keep your page specific CSS separate. You could also include the page specific CSS in the head of that particular page. This would reduce the number of requests per page load.

这篇关于每页一个样式表!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆