Solved

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

Posted on 2006-07-11
9
885 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
What is Backup? Backup software creates one or more copies of the data on your digital devices in case your original data is lost or damaged. Different backup solutions protect different kinds of data and different combinations of devices. For e…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

14 Experts available now in Live!

Get 1:1 Help Now