You are here: Re: cleaning up classes and ids in large site « HTML « IT news, forums, messages
Re: cleaning up classes and ids in large site

Posted by Ben C on 02/16/07 08:21

On 2007-02-16, dorayme <doraymeRidThis@optusnet.com.au> wrote:
> In article
><1171594920.245572.319460@s48g2000cws.googlegroups.com>,
> "windandwaves" <nfrancken@gmail.com> wrote:
>
>> Hi Folk
>>
>> I am managing a rather large site. Over time, the css file has gone
>> from a few lines to 15Kb of styles. I would really like to clean this
>> up and simplify it. Do you know of any systems / applications (I use
>> PHP for the site) that I can use to
>>
>> a. find all the IDs and classes used on the site.
>> b. check if these classes and IDs are listed in the css
>> c. find any classes and IDs listed in the css that are no longer used
>> on the site
>
> This is very easy technically. This is what I do: search for
> instances of ids and classes in the html files by using Search
> and Replace functions that come with any decent text editor. It
> should of course have search over whole folders (that includses
> all files in sub folders). If none are found, I search the css
> files and delete those ids or classes or otherwise attend to the
> matter. It really does not much matter if you conduct the search
> over the whole website folder and some of the found references
> are to css instances, you just see if there are references in
> both.
>
> If you are using php includes then of course, you will search the
> includes folder as well.

A less repetitive variant of the same idea:

1. Find all the occurrences in the html and save them to a file, using,
e.g. "grep -oP '(class|id)=".*?"' *.html > h"
2. Find all the occurrences in the css and save them to another file,
e.g. "grep -oP '[#\.](.*?)\s' tutorial.css > c". It may be your
editor can do these jobs just as well as grep.
3. Edit h and c to clean them up (yes the grep command could have been
cleverer, but this way is easier). And there will probably be a few
"false positives".
4. Do a unique sort on each of h and c. The command "sort h | uniq > hs;
mv hs h" for example, or I would use ":%!sort | uniq" in the editor.
5. Diff the files h and c. You can quickly see what classes/ids are in
one but not in the other.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация