如何有效地清理大型网站中的样式? [英] How can I effectively clean up styles in a large web site?

查看:124
本文介绍了如何有效地清理大型网站中的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的网站在过去五年的不断发展。发生时,网站的几乎所有样式都在一个大的CSS文件中。随着时间这个css文件已经增长到约9000行 - 我相信这些样式中的一些不再使用,并且很多样式提供重复的功能。



该网站是用PHP / Smarty编写的;有超过300个smarty模板,整个网站包含超过1000个不同的页面(读取 - 唯一的URL)。



清除此文件的最佳方法是什么?



更新:不幸的是,我放入网址的在线解析器不适用于我,因为75%的网站背后的用户名/密码登录 - 根据登录,是六个不同的角色,每个角色都有自己的一组页面。还有事务元素(在线商店),其中在(例如)信用卡支付被采取/处理之后显示页面。我怀疑任何在线工具将能够处理任何这些。因此,如果有一个工具,它必须在源代码树上工作。

解决方案

手动搜索文件中的选择器,我没有看到任何其他方式。



你当然可以使用 Dust-Me选择器,但你仍然必须浏览使用.tpl文件的每个页面(不是每个URL,因为我知道其中许多都是重复的)。

听起来像一个很大的工作!






另一个工具是Firebug插件名为 CSS使用。就我的阅读,它可以在多个网页上工作,但如果在网站范围内使用可能会中断。 //unused-css.com/\">不使用CSS在线工具。键入你的索引url到字段,瞧,几分钟后,所有使用的选择器列表:)我知道你想要未使用的,但然后唯一的工作是找到文件中的未使用的(ctrl + f)和删除它们:)



请务必使用第二选项,他们会向您发送整个网页抓取结果的电子邮件。可能需要半小时,但这远远好于一个星期。拿一些咖啡:)



只是测试了,工作原理:)


Our web site has been under a constant development for a better part of the last five years. As it happens, pretty much all the styles for the site are in one big CSS file. With time this css file has grown to about 9,000 lines - and I'm sure some of those styles are not used any more and quite a few styles provide duplicate functionality.

The site is written with PHP/Smarty; there are over 300 smarty templates and the whole site contains over 1000 different pages (read - unique URLs). I'm sure it will continue growing - as will the CSS file.

What's the best way to clean up this file?

Update: Unfortunately, online parsers where I put in a URL won't work for me, as 75% of the site is behind username/password logins - and depending on login, there are half a dozen different roles, each of which has their own set of of pages. There are also transactional elements (online shop), where the pages are displayed after (for example) credit card payment is taken/processed. I doubt that any online tool would be able to handle any of these. Therefore if there's a tool, it would have to work on a source tree.

解决方案

Short of going through each .tpl file and searching the file for the selectors manually, I don't see any other way.

You could of course use Dust-Me selectors, but you'd still have to go through each page that uses the .tpl files (not each url as I know that many of them will be duplicates).

Sounds like a big job! I had to do it once before and I did exactly that, took me a week.


Another tool is a Firebug plugin called CSS Usage. As far as I read it can work across multiple pages but might break if used site-wide. Give it a go.


Triumph! Check out the Unused CSS online tool. Type your index url into the field and voila, a few minutees later a list of all the used selectors :) I know you want the unused ones, but then the only work is finding the unused ones in the file (ctrl+f) and removing them :)

Make sure to use the 2nd option, they'll email you the results of the crawl of your entire webpage. Might take up to half an hour, but that's far better than a week. Take some coffee :)

Just tested it, works a treat :)

这篇关于如何有效地清理大型网站中的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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