You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've included a css compression method that runs just before the css view gets saves into simplecache:
Elgg 1.7 (with all modules enabled), no compression:
98KB
Elgg 1.7 (with all modules enabled), with compression:
82KB
Which saves (in this case) 16KB per hit, on the site i'm developing with more modules it saves a larger 25KB per page hit, probably more for more complex sites.
I modified the elgg_view_regenerate_simplecache() to do this following:
/**
* Regenerates the simple cache.
*
* see elgg_view_register_simplecache
*
*/
function elgg_view_regenerate_simplecache() {
global $CONFIG;
// todo elgg_view() checks if the page set is done (isset($CONFIG->pagesetupdone)) and
// triggers an event if it's not. Calling elgg_view() here breaks submenus
// (at least) because the page setup hook is called before any
// contexts can be correctly set (since this is called before page_handler()).
// To avoid this, lie about $CONFIG->pagehandlerdone to force
// the trigger correctly when the first view is actually being output.
$CONFIG->pagesetupdone = TRUE;
if (isset($CONFIG->views->simplecache)) {
if (!file_exists($CONFIG->dataroot . 'views_simplecache')) {
mkdir($CONFIG->dataroot . 'views_simplecache');
}
if (!empty($CONFIG->views->simplecache) && is_array($CONFIG->views->simplecache)) {
foreach($CONFIG->views->simplecache as $view) {
$viewcontents = elgg_view($view);
if ($view == 'css') {
$viewcontents = compress_css($viewcontents);
}
$viewname = md5(elgg_get_viewtype() . $view);
if ($handle = fopen($CONFIG->dataroot . 'views_simplecache/' . $viewname, 'w')) {
fwrite($handle, $viewcontents);
fclose($handle);
}
}
}
datalist_set('simplecache_lastupdate', 0);
}
unset($CONFIG->pagesetupdone);
}
/* compress css content - see http://websitetips.com/articles/optimization/css/crunch/ */
function compress_css($buffer) {
/* remove comments */
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
/* remove tabs, spaces, new lines, etc. */
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
/* remove unnecessary spaces */
$buffer = str_replace('{ ', '{', $buffer);
$buffer = str_replace(' }', '}', $buffer);
$buffer = str_replace('; ', ';', $buffer);
$buffer = str_replace(', ', ',', $buffer);
$buffer = str_replace(' {', '{', $buffer);
$buffer = str_replace('} ', '}', $buffer);
$buffer = str_replace(': ', ':', $buffer);
$buffer = str_replace(' ,', ',', $buffer);
$buffer = str_replace(' ;', ';', $buffer);
return $buffer;
}
Original ticket http://trac.elgg.org/ticket/1962 on 40188001-05-03 by trac user milan, assigned to unknown.
Elgg version: 1.7
I've included a css compression method that runs just before the css view gets saves into simplecache:
Elgg 1.7 (with all modules enabled), no compression:
98KB
Elgg 1.7 (with all modules enabled), with compression:
82KB
Which saves (in this case) 16KB per hit, on the site i'm developing with more modules it saves a larger 25KB per page hit, probably more for more complex sites.
I modified the elgg_view_regenerate_simplecache() to do this following:
see this link as reference:
http://websitetips.com/articles/optimization/css/crunch/
The text was updated successfully, but these errors were encountered: