Fri 22 Aug 2008
Sometimes the resultant HTML from JSP files has too much white space. This is because a lot of JSP logic will end up in only a few lines of actual HTML code and the rest is white space.
One efficient way to get rid of white space is to add this configuration to your web.xml on Tomcat/JBoss as described in this article, Trim Spaces in your JSP’s HTML.
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>
However this sometimes has undesired side-effects. For example this DSP:
<div class="foo"> <dspel:valueof param="displayName" /> </div>
causes this undesired result:
<div class="foo"/> Frank Kim
The work around is to do this.
<dspel:getvalueof var="displayName" param="displayName" />
<div class="foo"><c:out value="${displayName}"/></div>
The above problem might have been happening because we are running with a version of ATG that is for Servlet 2.3 but we are running with a version of JBoss that runs with Servlet 2.4.
There is another tip on removing white space in this JSP FAQ: Why I am getting extra whitespace in the output of my JSP? In our code we had one file which included a bunch of tag libraries. It originally looked like this.
<%/** Taglibs.jsp: include to pull in all taglibs */%>
<%@ taglib uri="/dspELTaglib" prefix="dspel" %> <%@ taglib uri="/jstlCoreTaglib" prefix="c" %> <%@ taglib uri="/struts-bean" prefix="bean" %> <%@ taglib uri="/struts-tiles" prefix="tiles" %
When we changed it to this we saved about 5% in terms of page size in bytes.
<%@ taglib uri="/dspELTaglib" prefix="dspel" %><%@ taglib uri="/jstlCoreTaglib" prefix="c" %><%@ taglib uri="/struts-bean" prefix="bean" %><%@ taglib uri="/struts-tiles" prefix="tiles" %>
You can use this tip with a DSP page and maintain indentation.
<dspel:page ><dspel:droplet name="/betweengo/droplet/Foo" ><dspel:oparam name="output" >Name: <dspel:valueof param="name" /></dspel:oparam ></dspel:droplet ></dspel:page>