首页 > 编程知识 正文

清理垃圾代码bat,清理垃圾代码3d

时间:2023-05-06 02:31:19 阅读:236610 作者:3969

清理垃圾代码
清理垃圾代码是指删除页面中的冗余代码。一个页面经过垃圾代码清理以后,可以删除接近80%的冗余代码。然而,什么样的代码才是垃圾代码呢?
1. 垃圾代码简介
垃圾代码就是指那些在删除的情况下也不会影响页面正常显示的非必要的代码。这些代码占据着庞大的空间,不但耗费用户下载页面的时间,还占用搜索引擎巨大的储存空间及增加搜索引擎分析数据的时间。然而,这么庞大的垃圾代码是如何产生的呢?
2. 垃圾代码的产生
一般情况下,我们会使用网页制作软件制作网页,如:Fontpage,Word 及 Dreamweaver。这些网页制作软件在制作网页的时候,会生成相应的HTML代码,其中大部分是必须的,而有一小部分则是可有可无,这就是所谓的垃圾代码。因此,避免产生垃圾代码最好的办法就是以手工编写代码的方式制作网页。
即使是同样内容的网页,使用不同的网页制作软件进行制作,所产生的代码也会存在很大的区别。例如:对于包含以下内容的网页:“我做的第一个网页”。使用Word制作会产生103行代码,共2.96 K的内容;Fontpage则产生17行代码,共308 字节内容;而使用Dreamweaver只产生12行代码,275的字节的内容。如下面代码所示:
Word
如下所示是使用Word制作网页时所产生的HTML代码,代码中包含了作者、版本、建立日期、最新更新日期、公司名称等标签及内容,其中绝大部分内容不管是对普通用户还是搜索引擎都毫无意义的。
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=GB2312">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">
<link rel=File-List rel="external nofollow" href="./1.files/filelist.xml">
<title>我做的第一个网页</title>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>rzdmla</o:Author>
  <o:Template>Normal</o:Template>
  <o:LastAuthor>rzdmla</o:LastAuthor>
  <o:Revision>1</o:Revision>
  <o:TotalTime>0</o:TotalTime>
  <o:Created>2008-03-13T14:06:00Z</o:Created>
  <o:LastSaved>2008-03-13T14:06:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Lines>1</o:Lines>
  <o:Paragraphs>1</o:Paragraphs>
  <o:Version>9.2812</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:PunctuationKerning/>
  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
  <w:Compatibility>
   <w:SpaceForUL/>
   <w:BalanceSingleByteDoubleByteWidth/>
   <w:DoNotLeaveBackslashAlone/>
   <w:ULTrailSpace/>
   <w:DoNotExpandShiftReturn/>
   <w:AdjustLineHeightInTable/>
   <w:UseFELayout/>
  </w:Compatibility>
 </w:WordDocument>
</xml><![endif]-->
<style>
<!--
 /* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
 /* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
 /* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:42.55pt;
mso-footer-margin:49.6pt;
mso-paper-source:0;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=ZH-CN style='tab-interval:21.0pt;text-justify-trim:punctuation'>
<div class=Section1 style='layout-grid:15.6pt'>
<p class=MsoNormal><span style='font-size:9.0pt;mso-bidi-font-size:12.0pt;
font-family:宋体;mso-ascii-font-family:Arial;mso-妩媚的睫毛膏-font-family:Arial;
color:gray'>我做的第一个网页</span></p>
</div>
</body>
</html>
Fontpage
如下所示是使用Fontpage制作网页时所产生的HTML代码。尽管比较简洁,但还是存在一些可有可无的标签及内容,例如:Generator(生成器)及Progid等。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>我做的第一个网页</title>
</head>
<body>
<p>我做的第一个网页</p>
</body>
</html>
Dreamweaver
使用Dreamweaver制作的页面所产生的代码是这三者中最简洁的。但是,却缺少一些非常重要的标签及内容,例如:“Description”及“Keywords”标签。
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=gb2312”>
<title>无标题文档</title>
</head>
<body>
我做的第一个网页
</body>
</html>
从上面例子中,我们可以看到使用Dreamweaver制作网页时所产生的代码量是最少的。因此,在没有掌握手工编写代码前,我们可以使用Dreamweaver制作网页,完成后再清理其中的垃圾代码。

尽管不同的软件制作网页时所产生代码会存在很大的差别,但有一部分代码是共有的,包括垃圾代码。


版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。