Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-07-11
9
Medium Priority
?
895 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 28

Assisted Solution

by:rrz
rrz earned 120 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 60 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 75 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Assisted Solution

by:colr__
colr__ earned 60 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 28

Assisted Solution

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

Assisted Solution

by:bloodredsun
bloodredsun earned 60 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

Industry Leaders: 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!

Question has a verified solution.

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

Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 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