To compress CSS files, you need to determine the heaviest CSS files. If you compress them, you save some significant kilobytes in loading. For the test website, default.css is the heaviest. Looking at the source code: <link rel="stylesheet" href="http://www.php-developer.org/wp-content/themes/arras-theme.1.3.5/css/styles/default.css" type="text/css" media="screen" /> It appears to be located in the css/styles directory. Using your FTP, download and then open it. Copy and paste the code below to the top most part:
<?php require_once("gzipCSS.php"); ?>
After that; save the file now as default.php and upload it back to the same directory from where it was downloaded. Edit the reference of the stylesheet in your header.php to:
<link rel="stylesheet" href="http://www.php-developer.org/wp-content/themes/arras-theme.1.3.5/css/styles/default.php" type="text/css" media="screen" />
The gzip compression code located in gzipCSS.php will be parsed by the server because of default.php, thus compressing the CSS containing it. The following is the script for gzipCSS.php (copy and paste this to your PHP editor and save as gzipCSS.php):
<?php //PHP gzip method ob_start ("ob_gzhandler");
//Header to tell browser what kind of file it is. header("Content-type: text/css; charset: UTF-8");
//Caching header("Cache-Control: must-revalidate"); $expires = "Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT"; header($expires); ?>
Credits: gzipCSS.PHP script by http://www.devirtuoso.com/2009/07/how-to-compress-cssjavascript-files-with-php/ It starts by loading the PHP GZIP handler, which will do the compression and then tell the browser it is a CSS file. Upload gzipCSS.php to the same directory as default.php, for example:
You can perform the same process with the rest of your heavy CSS files; the same concept can even be applied to JavaScript.
blog comments powered by Disqus |
|
|
|
|
|
|
|