trim whitespace from jsps

P

Peter Horlock

Hi, I want to remove all unnessary white spaces from my jsps (to
reduce file size and for search engine optimization...)

I found the Tomcat param (web.xml):
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>

Which does a nice job - but for some reason it even removes spaces it
should NOT!!
The problem (and a few work arrounds a didn't like too much) is
described in more detail here:
http://raibledesigns.com/rd/entry/trim_spaces_in_your_jsp1

Any other ideas of how to fix this?
&nbsp; and so on doesn't really get you a clean html code...,
<c:eek:ut value=""/> and so on will clutter your jsp code...

Maybe this problem is fixed with Tomcat 6.x?

Any other solutions of how to get this done?

Thanks in advance,

Peter
 
D

Dave Miller

Peter said:
Hi, I want to remove all unnessary white spaces from my jsps (to
reduce file size and for search engine optimization...)

I found the Tomcat param (web.xml):
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>

Which does a nice job - but for some reason it even removes spaces it
should NOT!!
The problem (and a few work arrounds a didn't like too much) is
described in more detail here:
http://raibledesigns.com/rd/entry/trim_spaces_in_your_jsp1

Any other ideas of how to fix this?
&nbsp; and so on doesn't really get you a clean html code...,
<c:eek:ut value=""/> and so on will clutter your jsp code...

Maybe this problem is fixed with Tomcat 6.x?

Any other solutions of how to get this done?

Thanks in advance,

Peter
I don't have an answer for you, rather two questions. How much file
space do you save (total with and without) and (OT) how does whitespace
reduction help with SEO?
 
P

Peter Horlock

Hi Dave,

I haven't measured file space reduction yet - however I am sure you
won't save that much, and you will
save more if you turn on gzip compression (but saving some space doesn't
hurt either, the smaller your pages are, the faster clients will receive
them...)
Concerning SEO, we are creating webpages based on data in our database
- the entire content is database based - the title tag, description tag,
well, really, all content.
Anyway, so the title tag is generated in a loop,
and as it is programmed using a JSTL for loop, the title is divided into
several lines. For some weird reason the G. Bot is to stupid or to lazy
to parse the entire tile tag => We need to find a way to write the
entire title (and the other meta tags too) in one single line.

Peter
 
D

Daniel Pitts

Peter said:
Hi Dave,

I haven't measured file space reduction yet - however I am sure you
won't save that much, and you will
save more if you turn on gzip compression (but saving some space doesn't
hurt either, the smaller your pages are, the faster clients will receive
them...)
Concerning SEO, we are creating webpages based on data in our database
- the entire content is database based - the title tag, description tag,
well, really, all content.
Anyway, so the title tag is generated in a loop,
and as it is programmed using a JSTL for loop, the title is divided into
several lines. For some weird reason the G. Bot is to stupid or to lazy
to parse the entire tile tag => We need to find a way to write the
entire title (and the other meta tags too) in one single line.

Peter
The problem is that either Space Is Important, or Space Is Not
Important, you can't have it both ways.

In my opinion, this is a flaw with most template based languages (JSP,
PHP, Freemarker, Velocity, etc...)

One approach, which is still kind of ugly, but it works:

<%----%><c:forEach ...><%--
--%>Some thing that is repeated<%--
--%></c:forEach>

This allows you to keep some basic formatting while reducing whitespace.

The other alternative is to avoid using templates, and build up a DOM
Document programamtically, and then serialize the DOM as a text-stream.
This has quite a few disadvantages, but it is the "cleanest" output
(it ensures proper encoding and markup syntax).

Hope this helps,
Daniel.
 
P

Peter Horlock

Daniel said:
The problem is that either Space Is Important, or Space Is Not
Important, you can't have it both ways.
Well I never said I would not need ANY space (everyone needs SOME space!
;-)

The problem is that the words sometimes willbeputtogetherlikethisline...
One approach, which is still kind of ugly, but it works:

<%----%><c:forEach ...><%--
--%>Some thing that is repeated<%--
--%></c:forEach>

Do you want to say "fill the remaining space with jsp comments"?
Not a bad idea. Will try this on Monday.

Thanks,

Peter
 
P

Peter Horlock

Hi Dave, in the meantime, I measured the file space savings:
~2,4 % for a big html page (433 lines vs. 258 lines of html).
When I manually compressed both these pages, it still saved 1,9 %.

So in conclusion, it's not that much, yet it's still something,
whether you are sending compressed pages or not.
For a big website like ours, this will save a few GBs of traffic, and
every page will load just a tiny bit faster for every single client -
all this by just adding 4 extra lines to your tomcat's web.xml.

However, turning on html compression will reduce file size by 70%!

Peter
 
D

Dave Miller

Peter said:
Hi Dave, in the meantime, I measured the file space savings:
~2,4 % for a big html page (433 lines vs. 258 lines of html).
When I manually compressed both these pages, it still saved 1,9 %.

So in conclusion, it's not that much, yet it's still something,
whether you are sending compressed pages or not.
For a big website like ours, this will save a few GBs of traffic, and
every page will load just a tiny bit faster for every single client -
all this by just adding 4 extra lines to your tomcat's web.xml.

However, turning on html compression will reduce file size by 70%!

Peter
Thanks, Peter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top