Author |
Message |
gazj
Worker
![Worker Worker](modules/Forums/images/ranks/3stars.gif)
![](modules/Forums/images/avatars/Animaniacs/Animaniacs_-_Brain.gif)
Joined: Apr 28, 2006
Posts: 152
Location: doncaster england
|
Posted:
Wed Aug 26, 2009 1:39 am |
|
hey guys i came accross this result by mistake after using this method to compress my html includes in my theme i noticed that the memory usage dropped upta 40% on my site by the time i finished adding it to various places.
Right lets begin
first the function to place in the mainfile.php
Code:function minit($min) {
// remove comments
$min = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $min);
// remove tabs, spaces, newlines, etc.
$min = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $min);
return $min;
}
|
stay in mainfile and find the function blockfileinc
find:
Code: if (empty($content)) {
$content = _BLOCKPROBLEM2;
}
|
below add:
Code:$content = minit($content);
|
save and close
open the theme.php and on all the inclides for the html files using this method
Code: $tmpl_file = 'themes/'.$ThemeSel.'/story_page.htm';
$thefile = implode('', file($tmpl_file));
$thefile = addslashes($thefile);
$thefile = "\$r_file=\"".$thefile."\";";
eval($thefile);
echo $r_file;
|
above the last line the echo add:
Code:$r_file = minit($r_file);
|
all comments and lines are removed reducing the number of lines outputted from these parts edited someone give it a try |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm
![](modules/Forums/images/avatars/5ed231554a8492e2e09da.gif)
Joined: Aug 13, 2009
Posts: 1123
|
Posted:
Wed Aug 26, 2009 7:44 am |
|
Where exactly I should place this function
Code:function minit($min) {
// remove comments
$min = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $min);
// remove tabs, spaces, newlines, etc.
$min = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $min);
return $min;
}
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
gazj
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Wed Aug 26, 2009 10:23 am |
|
i placed it in the bottom of my mainfile.php just before the case for the gfx image |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
evaders99
Former Moderator in Good Standing
![](modules/Forums/images/avatars/803d73f6452557b947721.jpg)
Joined: Apr 30, 2004
Posts: 3221
|
Posted:
Wed Aug 26, 2009 7:43 pm |
|
At the cost of CPU cycles. For websites where the page essentially its processed and sent to the user, thus the memory discarded, this doesn't really save much. Page loading time is not worth the expense.
You could easily optimize your external files by removing those spaces... but you lose the flexibility to edit them. I prefer to go for usability and documentation rather than figure out every little trick to compress data. |
_________________ - Only registered users can see links on this board! Get registered or login! -
Need help? Only registered users can see links on this board! Get registered or login! |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
Site Admin/Owner
![](modules/Forums/images/avatars/45030c033f18773153cd2.gif)
Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Wed Aug 26, 2009 8:53 pm |
|
While I agree with Evaders, it is a good tip if you are running on a system that is memory constrained. Thanks! |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
gazj
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Wed Aug 26, 2009 9:58 pm |
|
Evaders i used this as an alternative to removing them manually it also removes html and css comments im sure there can be many other ways to compress data but this i feel is the best way with out compramising the code and on pages with many hundreds maybe thousands of lines it can reduce the output of lines by around 30% +
Raven im sure you have in your time worked on sites or had site owners with sites on poor hosting and this would be a good way to cut out some of the hanging that comes with memory usage overload and if just 10% of sites on a single server used this method im sure server masters would see a big drop in memory usage |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
|