473,549 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strip space before page rendering

Is there any benefit to stripping all the space from the page before
rendering by overriding the page render and using the htmltextwriter and
stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
that may site's source code is like this. Is this because it is better for
the browser or harder for someone to be able to read it. Or maybe there is a
method or command to do this automatically?

Any thoughts are appreciated.

Mike
Nov 17 '05 #1
5 2182
saves bandwidth mainly...
"vMike" <Mi************ @gewarren.com.n ospam> wrote in message
news:bn******** **@ngspool-d02.news.aol.co m...
Is there any benefit to stripping all the space from the page before
rendering by overriding the page render and using the htmltextwriter and
stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
that may site's source code is like this. Is this because it is better for
the browser or harder for someone to be able to read it. Or maybe there is a method or command to do this automatically?

Any thoughts are appreciated.

Mike

Nov 17 '05 #2
I don't think there is a way to do it automatically, but it's simple enough
to implement.

This is the approach I use:

I have a base class derived from System.Web.UI.P age and override Render

namespace DoNot.Invade.My Space
{
class Page : System.Web.UI.P age
{
protected override void Render(HtmlText Writer writer)
{
StringBuilder sb = new StringBuilder() ;
StringWriter sw = new StringWriter(sb );
HtmlTextWriter hw = new HtmlTextWriter( sw);

base.Render (hw);

string html = sb.ToString();

html = html.Replace(En vironment.NewLi ne, string.Empty);
html = html.Replace("\ n", string.Empty); // This may be redundant
html = html.Replace("\ t", string.Empty);

writer.Write(ht ml);
}
}
}

Hope this helps
Brian W

"vMike" <Mi************ @gewarren.com.n ospam> wrote in message
news:bn******** **@ngspool-d02.news.aol.co m...
Is there any benefit to stripping all the space from the page before
rendering by overriding the page render and using the htmltextwriter and
stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
that may site's source code is like this. Is this because it is better for
the browser or harder for someone to be able to read it. Or maybe there is a method or command to do this automatically?

Any thoughts are appreciated.

Mike

Nov 17 '05 #3
Thanks, I had something similar to that. The only thing I had to do was do
remove the <!-- that asp puts before the javascipt for postback because when
I removed the rest of the line is caused an error. But I wonder is stripping
the space make the page display any quicker in the browser as I image there
is a small amount of overhead on the server side.

"Brian W" <brianw@gold_de ath_2_spam_rush .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I don't think there is a way to do it automatically, but it's simple enough to implement.

This is the approach I use:

I have a base class derived from System.Web.UI.P age and override Render

namespace DoNot.Invade.My Space
{
class Page : System.Web.UI.P age
{
protected override void Render(HtmlText Writer writer)
{
StringBuilder sb = new StringBuilder() ;
StringWriter sw = new StringWriter(sb );
HtmlTextWriter hw = new HtmlTextWriter( sw);

base.Render (hw);

string html = sb.ToString();

html = html.Replace(En vironment.NewLi ne, string.Empty);
html = html.Replace("\ n", string.Empty); // This may be redundant
html = html.Replace("\ t", string.Empty);

writer.Write(ht ml);
}
}
}

Hope this helps
Brian W

"vMike" <Mi************ @gewarren.com.n ospam> wrote in message
news:bn******** **@ngspool-d02.news.aol.co m...
Is there any benefit to stripping all the space from the page before
rendering by overriding the page render and using the htmltextwriter and
stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed that may site's source code is like this. Is this because it is better for the browser or harder for someone to be able to read it. Or maybe there
is a
method or command to do this automatically?

Any thoughts are appreciated.

Mike


Nov 17 '05 #4
Brian W wrote:
I don't think there is a way to do it automatically, but it's simple enough
to implement.

This is the approach I use:

I have a base class derived from System.Web.UI.P age and override Render

namespace DoNot.Invade.My Space
{
class Page : System.Web.UI.P age
{
protected override void Render(HtmlText Writer writer)
{
StringBuilder sb = new StringBuilder() ;
StringWriter sw = new StringWriter(sb );
HtmlTextWriter hw = new HtmlTextWriter( sw);

base.Render (hw);

string html = sb.ToString();

html = html.Replace(En vironment.NewLi ne, string.Empty);
html = html.Replace("\ n", string.Empty); // This may be redundant
html = html.Replace("\ t", string.Empty);

writer.Write(ht ml);
}
}
}

You'll want to be careful with simplistic code like this. There are
times when whitespace and newlines are significant, such as text inside
of a <pre> element or script code.

Hope this helps
Brian W

"vMike" <Mi************ @gewarren.com.n ospam> wrote in message
news:bn******** **@ngspool-d02.news.aol.co m...
Is there any benefit to stripping all the space from the page before
rendering by overriding the page render and using the htmltextwriter and
stringbuild er to strip linefeeds, tabs and extra space etc. I have noticed
that may site's source code is like this. Is this because it is better for
the browser or harder for someone to be able to read it. Or maybe there is


a
method or command to do this automatically?

Any thoughts are appreciated.

Mike



--
mikeb

Nov 17 '05 #5
True, I guess I should have mentioned that. Since the site I'm currently
working on doesn't use <pre> I don't worry about it. And what I have written
can be expanded upon to handle these situations.

There are other cases where this is a problem too. Such as the following:

<p>
This is
some text
</p>

will produce the following output:

This issome text

For me, though, I just edit the html and make sure there is also a space
before the newline.

Regards
Brian W
"mikeb" <ma************ @mailnull.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Brian W wrote:
I don't think there is a way to do it automatically, but it's simple enough to implement.

This is the approach I use:

I have a base class derived from System.Web.UI.P age and override Render

namespace DoNot.Invade.My Space
{
class Page : System.Web.UI.P age
{
protected override void Render(HtmlText Writer writer)
{
StringBuilder sb = new StringBuilder() ;
StringWriter sw = new StringWriter(sb );
HtmlTextWriter hw = new HtmlTextWriter( sw);

base.Render (hw);

string html = sb.ToString();

html = html.Replace(En vironment.NewLi ne, string.Empty);
html = html.Replace("\ n", string.Empty); // This may be redundant
html = html.Replace("\ t", string.Empty);

writer.Write(ht ml);
}
}
}


You'll want to be careful with simplistic code like this. There are
times when whitespace and newlines are significant, such as text inside
of a <pre> element or script code.

Hope this helps
Brian W

"vMike" <Mi************ @gewarren.com.n ospam> wrote in message
news:bn******** **@ngspool-d02.news.aol.co m...
Is there any benefit to stripping all the space from the page before
rendering by overriding the page render and using the htmltextwriter and
stringbuild er to strip linefeeds, tabs and extra space etc. I have noticedthat may site's source code is like this. Is this because it is better forthe browser or harder for someone to be able to read it. Or maybe there
is
a
method or command to do this automatically?

Any thoughts are appreciated.

Mike



--
mikeb

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2233
by: Malcolm Dew-Jones | last post by:
I am looking at xslt 1.0 and trying to understand if empty text nodes are supposed to be stripped or not as the default behaviour. 3.4 starts by listing rules for when white space is not stripped and then says "Otherwise the text node is stripped". which appears to contradict a later paragraph that discusses the details of the selection...
17
9103
by: Stanimir Stamenkov | last post by:
Is it possible to make two inline elements to appear adjacent stripping any white space appearing in between in the source? Example: <span class="adj">1</span> <span class="adj">2</span> <span class="adj">3</span> --
16
9242
by: Uncle Pirate | last post by:
This has me stumped. I am trying to use as little space as possible at the top of my document but Firefox/Mozilla insists on placing vertical space before any element. IE displays it correctly (as I want). At one point, I set some negative top margins which moved the graphics above the page in IE. Here's the link: http://abateofnm.org/ ...
38
23951
by: Xah Lee | last post by:
sometimes i wish to add white space in <p> as to achived effects similar to tab. what should i do? using empty image seems the sure way but rather complicated. (and dosen't change size with font) Woudl some of the space character in unicode work? (my html files uses unicode) Xah
6
2146
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows XP Pro SP 1, .Net Framework 1.1) and on our production server (Windows 2K SP 4, .Net Framework 1.1). I have simplified the code and data to isolate...
5
8708
by: dan.j.weber | last post by:
I'm using Python 2.3.5 and when I type the following in the interactive prompt I see that strip() is not working as advertised: >>>s = 'p p:p' >>>s.strip(' :') 'p p:p' Is this just me or does it not work? I want to get rid of all ' ' and ':' in the string. I've checked the doc and from what I can tell this is what strip() is supposed to...
6
2545
by: rtilley | last post by:
s = ' qazwsx ' # How are these different? print s.strip() print str.strip(s) Do string objects all have the attribute strip()? If so, why is str.strip() needed? Really, I'm just curious... there's a lot don't fully understand :)
4
2542
by: Adam Honek | last post by:
Hi all, The tool strip control is set to flow layout, no autosize and to anchor top, left. When the form is maximized all the icons and text fit in one line across the screen. The menu strip stays with the default height causing there to be a space from left to right under all icons.
11
12321
by: Mike Harrison | last post by:
Hi, I have some simple HTML like this: <div id="container" style="width:100%;"> <input type="text" <input type="button" style="float:right;" value="Click here..."> </div> I want the button to remain the normal size and be right-aligned, and the edit box to automatically take up the remaining width of the container.
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6041
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.