How would you do this...

B

Brian W

....or would you?

In order to minimize the number of bytes a pages consists of (to minimize
download time), and, admittedly, to disguise my HTML a little, all my pages
derive from a base class that I derived from Page.

In this class I override the Render method and do what is shown in the code
fragment below.

My intent is to remove all the stuff that doesn't affect the HTML output,
but this method does have it's problems.

1 ) When I newline or tab is in place that causes a space to be created
between words and when removed causes unwanted concatenation.
2 ) It doesn't take into consideration tags where these characters are
significant, such as in <pre> tags or script code.

Any thoughts?


TIA
Brian W


// Begin code fragment
protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);

base.Render (hw);

string html = sb.ToString();

if ( CompressOutput )
{
html = html.Replace(Environment.NewLine, string.Empty);
html = html.Replace("\n", string.Empty); // This may be redundant
html = html.Replace("\t", string.Empty);
}

writer.Write(html);
}
// End code fragment
 
A

Abhijeet Dev

Probably u want to replace repeated new line/tab characters with a single
one, not all of those.
 
K

Kevin Spencer

I wouldn't.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
A

Abhijeet Dev

ya .. actually its not required at all, it probably will increase the time
required to generate the page as against the time to download it, and even
if u have some 50 extra characters, it wont affect the total size
significantly. :)
 
K

Kevin Spencer

Unless the HTML is huge (which usually indicates bad design), a single JPEG
could be larger in bytes than the entire size of the page in HTML. Binaries
such as images, applets, ActiveX controls, etc, are your real hogs.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
J

Jeffrey Tan[MSFT]

Hi Brian,

Does the community's reply make sense to you?

If you need more help, please feel free to feedback. I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
B

Brian W

No, not really. Although I did deserve some of the responses since I added
"or would you" :)
 
J

Jeffrey Tan[MSFT]

Hi Brian,

Thanks very much for your feedback.

Actually, I agree with the community member's reply. There is no need for
you to do such thing. I know you want to reduce the page downloading time,
so you actaully want to improve the performance of the webform.

To improve the performance, you should concentrate on some other things,
such as:

Reduce the viewstate size
Avoid unnecessary postback
Reduce the exceptions
Use early binding instead of late binding

etc..

These are the main performance bottleneck of webform application. So you
should place your concern on these things. Although you can reduce a little
page downloading time through reducing page size, but the time your save
will spend on your html code processing. So you may not improve
performance.

There is a good article in MSDN shows you a general performance tips of
Asp.net WebForm, please refer to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconDevelopingHigh-PerformanceASPNETApplications.asp

Anyway, if you still want to do these things, I will give you some
suggestion:
1). For <pre> tag, you should parse the html string yourself, once find the
<pre> tag, preserve the content until meet next </pre>(You should also do
the same things for some other html element, such as <code> etc..)
2). You may remove "/t". For Environment.NewLine, I think you should only
remove where there are more than 1 Environment.NewLine(s), that is: only
persist one Environment.NewLine, so that the html source code will not
become one line.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Brian,

Glad to help you, you are welcome!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Top