Solved

Reducing the size of the rendered HTML by eliminating spaces??

Posted on 2006-07-11
9
891 Views
Last Modified: 2012-08-13
Hi experts,

We  have a JSP app that prints out large amount of data that we query from a database. The rendered HTML could get become pretty big (~18M). We found out that the file consists of at least 75% empty spaces and the only about 25% real content. We want to reduce the size of the HTML by eliminating the spaces.

1) Is there a line/command we can add to the top of the JSP to tell the server not to add spaces when rendering the JSP to HTML?

2) Or we will have to make the source JSP into one line of code so the indentation/visual structure will be gone. We don't want to do this as it would make the JSP unreadable.

Thanks
Stephen
0
Comment
Question by:autoknowledge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 27

Assisted Solution

by:rrz
rrz earned 40 total points
ID: 17081545
>1) Is there a line/command we can add to the top of the JSP to tell the server not to add spaces  
You might have to wait for  JSP 2.1 .  Look at
http://java.sun.com/developer/technicalArticles/J2EE/jsp_21/index.html     
So, soon we will be able to use  
<%@page trimDirectiveWhitespaces="true"%>
Sorry, I know that it doesn't help you now.
>We found out that the file consists of at least 75% empty spaces and the only about 25% real content.  
Wow, that seems excessive. Could you show us some of the offending code ? Maybe someone will have some ideas.
0
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 20 total points
ID: 17081938
as rrz points out, as of now the only way you have got is to remove all the empty lines you might have in your jsp page.. though its makes the jsp less readable but 18M of output is way too much of a output..
I am assuming that there must be a loop that is running & creating HTML..
you can take out all the indentation from that loop to compress it a bit...
0
 
LVL 19

Accepted Solution

by:
actonwang earned 25 total points
ID: 17082278
>>We want to reduce the size of the HTML by eliminating the spaces.

     One way you can do is to add a filter to remove all white space befor you send it back to client.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Assisted Solution

by:colr__
colr__ earned 20 total points
ID: 17082483
You could save all your html into a variable, then strip that variable of spaces before sending the whole thing to the client. The only problme with this is identifying which are sdpaces in ther code and which are spaces in the content you are generating (which you'll clearly want to keep:

String content = getAllTheHTML();
content += getMoreoftheHTML();
content += getMoreoftheHTML();
content += getMoreoftheHTML();

out.println(content.replaceAll(" ", ""));

This would certainly remove the white space, but would also remove the white space from your content.
0
 
LVL 19

Expert Comment

by:actonwang
ID: 17086497
filter, that is the solution.
0
 

Author Comment

by:autoknowledge
ID: 17102400
Could you further explain the filter approach here? Any pointers will be helpful too

Thanks
Stephen
0
 
LVL 27

Assisted Solution

by:rrz
rrz earned 40 total points
ID: 17103673
0
 
LVL 29

Assisted Solution

by:bloodredsun
bloodredsun earned 20 total points
ID: 17111011
I would agree in using a filter but a better regular expression for the replacement would be this

out.println(content.replaceAll("\\s+", " "));

as it takes all all contiguous whitespace in one go rather than only taking a nibble of 2 spaces at a time :-)
0
 

Author Comment

by:autoknowledge
ID: 17264825
We ended up using a 3rd party tool that eliminates the extra spaces offline before deploying the JSP into production and it works for us.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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