Help needed making my site faster

My elgg site is very slow so I want to make it faster, I have the codes, but I dont know where to insert them so please help me.

First of all to cache my site

$offset = 60 * 60 * 24; // Cache for a day
header(‘Content-type: text/css’);
header (‘Cache-Control: max-age=’ . $offset . ‘, must-revalidate’);
header (‘Expires: ‘ . gmdate (“D, d M Y H:i:s”, time() + $offset) . ‘ GMT’);


Whre do I insert these headers


Second is gzip compression I use this

if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start();


DO I have to add this in every file or just one or two main files will do the trick


Please reply A.S.A.P