Solved

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

Posted on 2006-07-11
9
888 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

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

13 Experts available now in Live!

Get 1:1 Help Now