Remove Whitespace From HTML / JSP / JSF

Remove Whitespace From HTML / JSP / JSF explains about implementing a servlet filter for removing whitespace & blank lines from your html/jsp/jsf output, which will reduce the payload and improve the overall web application performance

If you need a solution for below questions

How To Remove Whitespace From Response In Your Java Web Application?
How To Remove Whitespace From JSP/JSF And HTML?

then servlet filter will be the right choice, because by using servlet filter, we can implement this in a single place rather than on implementing every page

if you dont know about Servlet Filter, you can follow servlet filter Tutorial Here I am using, whitespace removing filter available from

By using this filter you can strip/trim whitespace & newline characters from your html/jsp/jsf pages without losing actual contents

Required Libraries

You need to download

  1. Tomcat 7

Following jar must be in classpath

  1. whitespacefilter.jar (I am created a jar file using

Package Structure

Remove Whitespace From HTML / JSP / JSF


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
	xmlns="" xmlns:web=""
	id="WebApp_ID" version="3.0">
	<display-name>whitespace Filter</display-name>
                  This filter class removes any whitespace from the response. It actually trims all
                  leading and trailing spaces or tabs and newlines before writing to the response stream.
                  This will greatly save the network bandwith, but this will make the source of the
                  response more hard to read.
Note is using this filter for optimizing the source code (please see the below screenshot)


Remove Whitespace From HTML / JSP / JSF

Your email address will not be published. Required fields are marked *