| CSS and JavaScript files are simple plain text files | | | | sets an expiration date far in the future (by defauly |
| with large amounts of unused space. Compressing all | | | | most browsers will not cache this file, but instead will |
| your style sheets into one page using PHP and gzip is | | | | reload it for every single page since it is a PHP script). |
| simple and can easily cut file download time in half | | | | The expiration date will ensure that the visitor to |
| (and reduce the number of files that need to be | | | | your site only downloads the file once. |
| downloaded). | | | | Finally, create an array with a list of the files you |
| First step: replace all your style sheet links in the head | | | | wish to compress, and use a for loop to output them |
| of your html document with a link to your new | | | | all - compressed. I managed to cut out about 50KB in |
| PHP-generated compressed style sheet. I keep all my | | | | this example, but the biggest advantage comes from |
| style sheets in a directory named "css", and the PHP | | | | reducing the number of file requests to the server |
| script is in the same directory and named "all.php". I | | | | (which will make a big difference even on the fastest |
| access this file just like a normal style sheet.if | | | | connections). |
| '], | | | | You can follow the exact same process for |
| r('Content-type: text/css');header('Expires: Fri, 21 Dec | | | | JavaScript, but make sure to change the |
| 2012 00:00:00 GMT'); | | | | Content-type header from text/css to text |
| $files = array('jquery.lightbox-0.5.css', 'main.css', | | | | javascript. Together these techniques can chop of |
| 'nav.css', 'content.css', 'objects.css');for ($file = 0; $file | | | | more than 50% of the size of your CSS and |
| The first four lines tell PHP to compress the file it | | | | JavaScript files and greatly reduce the number of |
| returns. The next line serves the file as CSS (even | | | | files a viewer must download. |
| though it has a PHP extension). The line after that | | | | |