GetSimple Support Forum

Full Version: How to compress HTML output?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please help me to compress the HTML output of the whole page by removing whitespaces and new lines. I tried using the below preg_replace function for compressing page content but nothing changed.

$mycontent = get_page_content();
preg_replace(“/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/”, “\n”, $mycontent);
im not good with regex, so i cant check that for you, but dont you need to echo the output created by preg_replace?
Instead of stripping whole document from white lines and spaces why don't you compress whole outputted data ?
Assuming you host yourself on a pretty good provider, such compression is turned on by default, and just investigate headers your browsers get.
If not, mod_deflate and mod_gzip are the solutions you are looking for.
Especially when it goes to compressing all data, not only stripping whitespaces from document Wink
i like yojoe's suggestion better too - plus it's easier to implement.
Yes, i echoed the output.
Actually I'm already compressing the HTML using gzip compression, browser caching, expiry on my nginx server at Linode. I want to further clean out the source to to save few additional bytes. Please let me know how to do that.
I found this persion (http://get-simple.info/forum/topic/2143/...re-output/) also trying to do what i want, but don't know where/how to implement that hook.
if you really are
nvinanda Wrote:already compressing the HTML using gzip compression, browser caching, expiry on my nginx server at Linode
i doubt you can get any real advantage by adding that function.

try http://gtmetrix.com/ and check you yspeed and google page speed scores. And do what they suggest.

additionally, care to post you nginx config file for getsimple ?

mine is here: http://get-simple.info/forum/topic/1374/gs-and-nginx/
marrco Wrote:additionally, care to post you nginx config file for getsimple ?
will surely do it as soon as i finish the setup.
nvinanda Wrote:I want to further clean out the source to to save few additional bytes. Please let me know how to do that.

You seem to be a pedantic webdev Smile
But your preg replace rule isn't working.

Two things:
1. get_page_content() echo'es the content right away, so you have to load page's content with your own function (or use a plugin)
2. you can't stripe all spaces

Below method is tested and marked as working:
Code:
$pagecontent = your_get_page_content_function(return_page_slug());
echo preg_replace(array('/\s{2,}/', '/[\t\n]/'), '', $pageconent);
It stripes new lines, multiple spaces, and tabs.