Posts: 31
Threads: 13
Joined: Apr 2011
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
Posts: 1,848
Threads: 86
Joined: Aug 2009
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!
Posts: 1,204
Threads: 30
Joined: Jun 2010
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
Addons: blue business theme, Online Visitors, Notepad
Posts: 1,848
Threads: 86
Joined: Aug 2009
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!
Posts: 31
Threads: 13
Joined: Apr 2011
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
Posts: 149
Threads: 12
Joined: Dec 2009
2011-06-27, 21:07:16
(This post was last modified: 2011-06-27, 21:09:46 by alex.drag.)
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/
Posts: 31
Threads: 13
Joined: Apr 2011
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
Posts: 1,204
Threads: 30
Joined: Jun 2010
2011-06-28, 04:47:28
(This post was last modified: 2011-06-28, 04:49:44 by BlackRose.)
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 Smile](http://get-simple.info/forums/images/smilies/smile.gif)
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