删除html标签之间的空格? [英] Removes spaces between html tags?

查看:351
本文介绍了删除html标签之间的空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了消除一些页面加载时间,我在哪里可以找到某些东西来删除html标签之间的空格?没有我必须通过每一个,并自己删除它们



像这样:

 <身体GT; 
< p> Lot's of space< / p>
< / body>

< body>< p>无空格< / p>< / body>

我发现这个网站。但它会在标签之间留下一个空间。但我不想要任何。

解决方案

请注意您对发生的事情有一些了解,否则将破坏文档的完整性。完全缩小的代码示例删除所有注释和空白字符,这些字符对于语法目的不是必需的。



换句话说,这个HTML示例:

 < p>某些内容
< strong>很强大< / strong>

< em>强调< / em>
。< / p>

完全缩小时:

 < p为H. somecontent写入<强> isstrong< /强>和< EM>强调< / EM> inthisparagraph< / p为H. 

在这种情况下,内容的损坏显而易见,因为所有单词相互碰撞。不明显的是空间缓冲内容和标签以及标签之间不与其他内容相邻的空间。 HTML文档中标签之外的所有空白字符都是DOM中的文本节点,如果不仔细考虑删除DOM节点可能会有害。另外,您还必须确保您的HTML缩小器不会破坏任何内嵌JavaScript或CSS代码。在查看可用的不同选项时仔细调查这些条件。



这是我写的一个可能对您有帮助的文章,因为它会以完全充分的方式缩小标记代码使用自动漂亮打印应用程序递归到美化状态。



http://prettydiff.com/?m=minify&html


To take away some page loading time, where can I find something to remove spaces between html tags? Without me having to go through each one and remove them myself

Like so:

<body>
  <p>Lot's of space</p>
</body>

<body><p>No space</p></body>

I found this site. But it leaves one space between tags. But I don't want any.

解决方案

Be careful that you have some idea of what is happening or you will corrupt the integrity of your documents. A fully minified code sample removes all comments and all white space characters not necessary for syntactical purposes.

In other words this example of HTML:

<p>Some content
    <strong>is strong</strong>
    and
    <em>emphasized</em>
    in this paragraph.</p>

When fully minified becomes:

<p>Somecontent<strong>isstrong</strong>and<em>emphasized</em>inthisparagraph.</p>

In that case the corruption to the content is obvious as all the words are colliding into each other. What is not obvious is the space buffering content and tags and the spaces between tags not adjacent to other content. All white space characters outside of tags in a HTML document are text nodes in the DOM and removing DOM nodes without careful consideration is possibly harmful.

Furthermore, you also have to ensure that your HTML minifier is not corrupting any inline JavaScript or CSS code. Investigate these conditions carefully when looking at the different options available.

Here is one that I wrote which may be helpful to you as it minifies markup tags in a way that is fully recursive to a beautified state using an automated pretty-print application.

http://prettydiff.com/?m=minify&html

这篇关于删除html标签之间的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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