这将是一个 HTML 缩小器,它会跳过 <%
和 %>
之间的所有内容。
实际上,开源 HTML 缩小器将是一个很好的起点,特别是如果它已经有代码来保留某些块的内容,例如
我知道 HTML 缩小器不太常见,因为它比 JS/CSS 更频繁地更改,并且通常是动态生成的,但如果可以让 JSP 编译器在生成其编译的缓存副本之前进行缩小,则将导致缩小的 HTML。
另外,ASP 缩小器可能非常接近同样的东西。而且我不关心对服务器有意义的自定义标签。对服务器(对于我的公司)而言唯一重要的内容是在 <%%>
块中。
This would be an HTML minifier that skips everything between <%
and %>
.
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.
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.
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.
发布评论
评论(4)
这个问题有点过时了,但是带有资源的答案仍然没有发布。
HtmlCompressor 使这一切成为可能,而且非常简单。
您可以通过 Java API 使用它:
或者您可以通过 Taglib 使用它:
在 JSP 中:
干杯
This question is a bit outdated but an answer with a resource still hasn't made it's way to the posting.
HtmlCompressor makes this very thing possible and quite simply.
You can use it via Java API:
Or you can use it via Taglib:
In JSP:
Cheers
JSP转换为Java 代码,然后编译为字节码。那么缩小 JSP 就没有意义了。
您可以通过编写自定义过滤器来处理 JSP 页面生成的输出。我已经编写了过滤器来修剪 JSP 输出中的空行和不必要的空格,不幸的是它不是公开的。但如果您四处搜索,我相信您可以找到 servlet 过滤器来从生成的 HTML 中删除不需要的内容。
JSP is transformed to Java code and subsequntly compiled to bytecode. Minifying JSP has no purpose then.
You can process output generated by JSP page by writing custom filter. I have written filter to trim empty lines and unnecessary whitespace from JSP output, unfortunately it's not public. But if you google around, I'm sure you can find servlet filters to remove unneeded stuff from generated HTML.
查看修剪过滤器 (http://www.servletsuite.com/servlets/trimflt. htm),您可以简单地将其映射到 web.xml 中。
它将帮助您删除空格,还可以删除注释。
根据我的经验,如果您使用本身没有任何输出的标签(例如 JSTL C 控制标签(c:if、c:choose、...)),JSP 中会出现大量空白,然后这会非常严重。便利。
Have a look at the Trim Filter (http://www.servletsuite.com/servlets/trimflt.htm), which you can simply map in your web.xml.
It will help you to remove whitespace, and can also strip off comments.
From my experience, whitespace occurs a lot in JSPs if you use tags that themselves don't have any output, such a the JSTL C control tags (c:if, c:choose, ...), and then this comes in very handy.
正如您所知,HTML 缩小不太常见,有时它还会导致错误,而不是从中获得任何好处。 HTML 也是动态生成的内容。
另一方面,有许多更好的方法来加速应用程序前端。
WebUtilities 是一个小型 Java 库,可帮助加快 J2EE Web 应用程序前端的速度。下面是链接。
采用新的 0.0.4 版本它进行了许多优化并显着提高了性能。如果您觉得有用,请看一下。
As you are already aware that HTML minification is less common and it also results in errors sometime than getting any benefit out of it. HTML is also dynamically generated content.
On the other hand, there are many better ways to speed up the application front end.
WebUtilities is a small java library to help speed up J2EE webapp front-end. Below is the link.
With new 0.0.4 version it does many optimization and results in significant performance boost. Please have a look in case you find it useful.