Help - Search - Member List - Calendar
Full Version: How to optimizing source code?
WorkTheWeb Forums > Webmaster Resources > Webmaster - General Help
Support our Sponsors!
Justin Sane
I'm used to using comments throughout my web pages, javascripts, CSS and
PHP source code. I also indent manually a lot (Dreamweaver MX 2004 fails
miserably BTW).

My question is: Can we save a few bits removing all indentation and
comments? It may not be significant but if one can save 2-3KB it would
already be worth it for high-traffic web sites, and thus savings on
bandwidth.

If it's possible, how can I automatically open all files of a folder and
clean them up? Is there a solution that does just that?

--
Thanks,

Justin.
http://www.opera.com/mail/

mbstevens
Justin Sane wrote:
QUOTE
I'm used to using comments throughout my web pages, javascripts, CSS
and  PHP source code. I also indent manually a lot (Dreamweaver MX 2004
fails  miserably BTW).

My question is: Can we save a few bits removing all indentation and
comments? It may not be significant but if one can save 2-3KB it would
already be worth it for high-traffic web sites, and thus savings on
bandwidth.

If it's possible, how can I automatically open all files of a folder
and  clean them up? Is there a solution that does just that?

Download HTML Tidy (you can find it through w3.org).

It is almost never a good idea to remove comments from code.
You can make indentation with a single tab to replace several
space characters. But you really won't be saving much. I would
focus my worry on other matters.

David Dorward
Justin Sane wrote:

QUOTE
My question is: Can we save a few bits removing all indentation and
comments?

You can probably save a lot more by using gzip compression. (mod_gzip if you
are an Apache user).

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is

Norman L. DeForest
On Sat, 2 Jul 2005, mbstevens wrote:

QUOTE
Justin Sane wrote:
I'm used to using comments throughout my web pages, javascripts, CSS
and  PHP source code. I also indent manually a lot (Dreamweaver MX 2004
fails  miserably BTW).

My question is: Can we save a few bits removing all indentation and
comments? It may not be significant but if one can save 2-3KB it would
already be worth it for high-traffic web sites, and thus savings on
bandwidth.

If it's possible, how can I automatically open all files of a folder
and  clean them up? Is there a solution that does just that?

Download HTML Tidy (you can find it through w3.org).
It is almost never a good idea to remove comments from code.
You can make indentation with a single tab to replace several
space characters.  But you really won't be saving much.  I would
focus my worry on other matters.

Well, if he uses point-and-click software that creates HTML atrocities
like this ("etc." means appropriate ( or inappropriate) markup I'm too
lazy to think of appropriate (or inappropriate) fake values for and type
in; '$' indicates long line gone past the edge of the screen as displayed
by PICO):

<body>
<table etc.>
<tr etc.>
<td etc.>
<table etc.>
<tr etc.>
<td etc.>
<font color=""000000">
<img src="http:$
<br>
Welcome to Foo $
</font>
</td>
<td etc.>
<font color=""000000">
<img src="http:$
</font>
<td etc.>
</tr>
</table>
</td>
</tr>
</table>

.... and so forth, and so forth, then stripping out leading spaces could
be very helpful. One >1000KB spam I got from Argentina was reduced to
about 50KB merely by stripping the leading spaces from all of the lines.
There were some lines almost 200 characters long with a single "</td>" or
"</tr>" or "<br>" at the end of the line being the only non-space
characters in the line.

And, yes, I have seen images wrapped in <font>...</font> tags too.

Now, if the page author creates the HTML by hand, and uses CSS properly
instead of the redundant styles for paragraphs followed by paragraphs
with style attributes that specify the same thing again and again with
a span tag nested inside of that specifyies more stuff again and again
as generated by Word that may reduce the overhead to begin with. An
example from spam (the faint of heart may wish to avert their eyes even
though I have snipped most of it):

: <style>
: <!--
: /* Style Definitions */
: p.MsoNormal, li.MsoNormal, div.MsoNormal
: {mso-style-parent:"";
: margin:0in;
: margin-bottom:.0001pt;
: mso-pagination:widow-orphan;
: font-size:12.0pt;
: font-family:"Times New Roman";
: mso-fareast-font-family:"Times New Roman";}
: p
: {margin-right:0in;
: mso-margin-top-alt:auto;
: mso-margin-bottom-alt:auto;
: margin-left:0in;
: mso-pagination:widow-orphan;
: font-size:12.0pt;
: font-family:"Arial Unicode MS";}
: -->
: </style>
: </head>
:
: <body lang=EN-US link="#003399" vlink=purple style='tab-interval:.5in'>
:
: <div class=Section1>
:
: <p align=center style='margin-top:12.0pt;margin-right:0in;margin-bottom:0in;
: margin-left:0in;margin-bottom:.0001pt;text-align:center;mso-line-height-alt:
: 14.4pt'><span style='font-size:16.0pt;mso-bidi-font-size:10.0pt;font-family:
: Arial;color:#333333'>Travel – M0NEY - Freedom <o:p></o:p></span></p>
:
: <p align=center style='margin-top:12.0pt;margin-right:0in;margin-bottom:0in;
: margin-left:0in;margin-bottom:.0001pt;text-align:center;mso-line-height-alt:
: 14.4pt'><span style='font-size:16.0pt;mso-bidi-font-size:10.0pt;font-family:
: Arial;color:#333333'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
:
: <p align=center style='margin:0in;margin-bottom:.0001pt;text-align:center;
: mso-line-height-alt:14.4pt'><span style='font-size:16.0pt;mso-bidi-font-size:
: 10.0pt;font-family:Arial;color:#333333'>The Perfect Home Business<o:p></o:p></span></p>
:
: <p class=MsoNormal><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
:
: <p class=MsoNormal><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
:
: </div>

While I'm at it, does anyone know what possible use there is for the
"<o:p></o:p>" tags?

--
Can you Change: MINDWORKS to MINDWORKS (* == Book)
*HALIFAX HALIFAX*
in 76 moves? Try http://www.chebucto.ns.ca/~af380/MHPuzzle.html
(Requires a browser supporting the W3C DOM such as Firefox or IE ver 6)

Beauregard T. Shagnasty
Norman L. DeForest wrote:
QUOTE
While I'm at it, does anyone know what possible use there is for
the "<o:p></o:p>" tags?

Your spam was created in a Microsloth product, most likely Word. All
that extraneous crap is so that the "saved as web page" document can
be *re-imported* into Word with all the styling intact.

Same with web sites where the unskilled use Word to create the pages.

--
-bts
-This space intentionally left blank.

Justin Sane
On Sat, 02 Jul 2005 14:25:37 -0300, Norman L. DeForest
<[Email Removed]> wrote:

QUOTE
While I'm at it, does anyone know what possible use there is for the
"<o:p></o:p>" tags?

I don't put crap into my code. I use Dreamweaver in code view and indent
using the TAB key. I use TopStyle and CSS to position elements inside my
pages. Average page weight is 5KB. But I want pages even lighter.

--
Thanks,

Justin.
http://www.opera.com/mail/

Justin Sane
On Sat, 02 Jul 2005 13:33:22 -0300, David Dorward <[Email Removed]>
wrote:

QUOTE
You can probably save a lot more by using gzip compression. (mod_gzip if
you are an Apache user).

Yes David, I use mod_gzip already and phpAccelerator. It helps.

--
Thanks,

Justin.
http://www.opera.com/mail/

mbstevens
Justin Sane wrote:

QUOTE
I don't put crap into my code. I use Dreamweaver in code view and
indent  using the TAB key. I use TopStyle and CSS to position elements
inside my  pages. Average page weight is 5KB. But I want pages even
lighter.


Do you have all display stuff out of your markup and all pages
accessing the same CSS file(s)? Most browsers can chche the first
access of the CSS file, so all subsequent page loads get it for
(virtually) free.

Justin Sane
On Mon, 04 Jul 2005 00:40:47 -0300, mbstevens
<[Email Removed]> wrote:

QUOTE
Do you have all display stuff out of your markup and all pages
accessing the same CSS file(s)?  Most browsers can chche the first
access of the CSS file, so all subsequent page loads get it for
(virtually) free.

Yes, just one style sheet, and no layout snippet into the XHTML page. Only
semantic markup.
For instance: http://www.acosmundial.com.br/novo/

--
Thanks,

Justin.
http://www.opera.com/mail/


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.