Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there such thing as a JSP minifier? (or Open Source HTML minifier)

Tags:

html

jsp

minify

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.

like image 520
700 Software Avatar asked Mar 30 '11 15:03

700 Software


People also ask

What is an HTML Minifier?

Minification refers to the process of removing unnecessary or redundant data without affecting how the resource is processed by the browser - e.g. code comments and formatting, removing unused code, using shorter variable and function names, and so on.

How do you minify a JSP file?

compress(html); 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.

How do you use a Minifier?

Go to minifycode.com and click the CSS minifier tab. Then paste the CSS code into the input box and click the Minify CSS button. After the new minified code is generated, copy the code. Then go back to the css file of your website and replace the code with the new minified version.

How does JavaScript Minifier work?

How Minification Works. Minification works by analyzing and rewriting the text-based parts of a website to reduce its overall file size. Minification extends to scripts, style sheets, and other components that the web browser uses to render the site. Minification is performed on the web server before a response is sent ...


1 Answers

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:

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

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.

In JSP:

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

Cheers

like image 177
Nicholas Anderson Avatar answered Oct 08 '22 12:10

Nicholas Anderson