Forum Moderators: phranque

Message Too Old, No Replies

My HTML Head is getting re-formatted?

         

thing3b

9:32 am on Apr 10, 2008 (gmt 0)

10+ Year Member



I like to try and reduce the bandwidth I am using. One way I do this is to remove a lot of the whitespace and returns from my HTML code. This is done by PHP. When I test my php script the entire head section of my html code is on one line.

When I run the same PHP code on my webhost (GoDaddy), every meta tag and link tag in the head section is on a new line. The webhost seems to be adding in extra returns into my HTML code.

I am aware that my webhost may be using a cache. Is it common for a cache or proxy server to do this?

Has anyone seen anything like this?

surrealillusions

11:03 am on Apr 10, 2008 (gmt 0)

10+ Year Member



as far as i know, adding returns to a page doesn't really add any extra bandwidth, or at least thats it not worth crying over.

Extra spaces though, these do help in writing and organising (same way as returns do) to help break uip the page. Depending on how much white space you have, is it worth getting rid of it?

:)

rocknbil

6:03 pm on Apr 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have large pages, *any* whitespace can add up to as much as 10-20K. If you're running really heavy pages, this indeed will save you some output size.

To your original problem, you're saying the PHP is removing the space? Are you sure there's some regexp not working correctly?

What's the platform, Linux? If you do, say, a replace for \n, it may need a \r or zero or more: \n\r*. Newline characters are different on Linux than PC newlines.

Last, for others that may help, is this a shared hosting account, VPS, or dedicated? I've got a dedi plan with GD and have seen no such anomaly.

thing3b

8:48 pm on Apr 10, 2008 (gmt 0)

10+ Year Member



Thanks rocknbil; forgot new lines. One of the scripts I am using was using the linux version of line returns and my PHP did not take this into account. (It worked perfectly, but only on Windows).

In regards to saving bandwidth, removing all returns, comments and spaces out of my html, css and js has saved me a lot of bandwidth. I like to leave a stack load of comments where I code and remove these comments by this method.

My 6 KB CSS file for example can be reduced down to 2 KB just by removing the comments and whitespace.