Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compress HTML output?
#1
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);
Using GetSimple 3.0
Reply
#2
im not good with regex, so i cant check that for you, but dont you need to echo the output created by preg_replace?
- Chris
Thanks for using GetSimple! - Download

Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Reply
#3
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
Addons: blue business theme, Online Visitors, Notepad
Reply
#4
i like yojoe's suggestion better too - plus it's easier to implement.
- Chris
Thanks for using GetSimple! - Download

Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Reply
#5
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.
Using GetSimple 3.0
Reply
#6
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/
Reply
#7
marrco Wrote:additionally, care to post you nginx config file for getsimple ?
will surely do it as soon as i finish the setup.
Using GetSimple 3.0
Reply
#8
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.
Addons: blue business theme, Online Visitors, Notepad
Reply




Users browsing this thread: 1 Guest(s)