有没有像JSP minifier这样的东西? (或开源HTML缩小器) [英] Is there such thing as a JSP minifier? (or Open Source HTML minifier)

查看:219
本文介绍了有没有像JSP minifier这样的东西? (或开源HTML缩小器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个HTML缩小器,可以跳过<%%> 之间的所有内容。

This would be an HTML minifier that skips everything between <% and %>.

实际上,一个开源HTML minifier会是一个很好的开始,尤其是如果它已经有代码来保存某些块的内容像< textarea 。它的代码也可以保留< %%> 块。

Actually, an Open Source HTML minifier would be a good starting place, especially if it already had code to preserve the contents certain blocks like <textarea. It's code might be able to be made to preserve <%%> blocks also.

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

I am aware that HTML minifiers are less common because that changes more often than JS/CSS and is often dynamically generated, but if the JSP compiler could be made to minify before making its compiled cache copy, it would result in minified HTML.

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

Also, an ASP minifier would probably be very close to the same thing. And I don't care about custom tags that have meaning to the server. The only stuff that matters to the server (for my company) is in the <%%> blocks.

推荐答案

这个问题有点过时,但回答 的资源仍然没有成功发布。

This question is a bit outdated but an answer with a resource still hasn't made it's way to the posting.

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

HtmlCompressor makes this very thing possible and quite simply.

您可以通过Java API使用它:

You can use it via 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使用它:

Or you can use it via 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>

干杯

这篇关于有没有像JSP minifier这样的东西? (或开源HTML缩小器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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