gpt4 book ai didi

html - 有没有像 JSP 压缩器这样的东西? (或开源 HTML 压缩器)

转载 作者:技术小花猫 更新时间:2023-10-29 12:26:06 29 4
gpt4 key购买 nike

这将是一个 HTML 压缩器,它会跳过 <% 之间的所有内容和 %> .

实际上,一个开源 HTML 压缩器将是一个很好的起点,特别是如果它已经有代码来保留某些 block 的内容,如 <textarea。 .它的代码可以用来保存 <%%> block 也。

我知道 HTML 缩小器不太常见,因为它比 JS/CSS 更频繁地更改并且通常是动态生成的,但是如果 JSP 编译器可以在制作其编译缓存副本之前缩小,它会导致缩小 HTML .

此外,ASP 缩小器可能非常接近同一事物。而且我不关心对服务器有意义的自定义标签。唯一对服务器(对于我的公司)重要的东西在 <%%> 中。 block 。

最佳答案

这个问题有点过时了,但是带有资源的答案仍然没有发布。

HtmlCompressor使这件事成为可能而且非常简单。

您可以通过 Java API 使用它:

String html = getHtml(); //your external method to get html from memory, file, url etc.
HtmlCompressor compressor = new HtmlCompressor();
String compressedHtml = compressor.compress(html);

或者你可以通过 Taglib 使用它:

Download .jar file of the current release and put it into your lib/ directory
Add the following taglib directive to your JSP pages:

<%@ taglib uri="http://htmlcompressor.googlecode.com/taglib/compressor" prefix="compress" %>

Please note that JSP 2.0 or above is required.

在 JSP 中:

<compress:html removeIntertagSpaces="true">
<!DOCTYPE html>
...
</html>
</compress:html>

干杯

关于html - 有没有像 JSP 压缩器这样的东西? (或开源 HTML 压缩器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5488592/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com