Solved

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

Posted on 2006-07-11
9
890 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
Technology Partners: 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
spring dependency injection using java config 2 91
love6 challenge java 31 133
designing in object programming 12 108
by zero exception 10 70
This article was initially published on Monitis Blog, you can read it here . When it comes to deciding which approach to website performance monitoring is best for your business, unfortunately, like so many options in life . . . it depends. In t…
This article discusses how to implement server side field validation and display customized error messages to the client.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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