Solved

Remove all extra white space of outbound pages Tomcat JSP

Posted on 2007-11-30
4
5,405 Views
Last Modified: 2013-12-02
I am trying to find a good easily implemented way to remove all extra unseen white space in  the HTML code being returned by tomcat to the client's computer. So for instance if there was a way to put a layer between tomcat and the and the user that just compresses the file by removing extra white space.

If you view source of say msn you will find no new lines or tabs. they strip all this out to try and reduce the download size of a page. Any suggestions on how to output a compressed file without having to update the source code for each page?
0
Comment
Question by:Isisagate
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 500 total points
ID: 20383419
You can write your JSP pages to reduce white space by putting JSP directives on the same line (no newlines).  For example,
<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1"%><%
 // code here
 // last code line here  %><html><head> [rest of page here]

It's harder for the programmer to read, which is why most people don't write JSP code that way.

You can add a filter to Tomcat to strip all unseen white space in the returned page.

For Tomcat 5.5+ you can add the trimSpaces param to your conf/web.xml and set it to true.

There is a great discussion about different ways to handle trimming white space from JSP pages here:
http://raibledesigns.com/rd/entry/trim_spaces_in_your_jsp


0
 
LVL 27

Expert Comment

by:rrz
ID: 20383705
JSP 2.1 has this. Does it help you ?
<%@ page trimDirectiveWhitespaces="true" %>
0
 
LVL 11

Author Closing Comment

by:Isisagate
ID: 31411930
Great solutions Exactly what I wanted
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 20385010
Great -- glad to help.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
changePi Challenge 15 124
stringclean challenge 26 74
ForLoop Example 3 48
null output 3 24
This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
This article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now