2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by opjjuly
1

you can specify filetypes for compression in apache's .htaccess file

<IfModule mod_gzip.c>     
mod_gzip_on       Yes     
mod_gzip_dechunk  Yes     
mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$   
mod_gzip_item_include handler   ^cgi-script$     
mod_gzip_item_include mime      ^text/.*     
mod_gzip_item_include mime      ^application/x-javascript.*     
mod_gzip_item_exclude mime      ^image/.*     
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* 
</IfModule>

which acts on all files of the designated extension or mime
the text above is from my .htaccess file
or in php on a per file basis
example style.css renamed to style.css.php

<?php header ('content-type:text/css');
ob_start("ob_gzhandler"); ?>
.rss-box {margin:1em 3%;padding:4px 8px;background-color:#ededed;border:2px dashed #7485CA;}
.rss-title, rss-title a {font-family:"American Typewriter", "Trebuchet MS", Trebuchet, Lucida, sans-serif;font-size:100%;font-weight:bold;margin:5px 0;padding:0;letter-spacing:1px;}
//huge amount of css
<?php ob_flush();?>

it may be more productive to combine the .js files and .css files into 1 if they are small,
other ways to speed up your site
http has limits on simultaneous file transfers from a single domain
create subdomains on your site, I have www pics img, as subdomains so can parallel 2 files from each subdomain (=6) instead of only 2 from www, all subdomsins point to the same root of mydomain.com keep paths constant

Edited by almostbob: n/a

0

thanks for the reply almostbob, im still new on this , i just heard of the gzip compression and thought i should ask. im more interested in php on a per file basis. where do i put the script? the same script can be used for Javascript as well?

0

the script is two lines at the start of each file
and 1 line at the end
in this case rename files *.js to *.js.php(so php will process the file, and alter calls in the header to .js.php)
and add the first two lines before and the third line after

<?php header ('content-type:text/javascript');
ob_start("ob_gzhandler"); ?>
<?php ob_flush();?>

for css rename *.css to *.css.php(so php will process the file, and alter calls in the header to .css.php)
and add the first two lines before and the third line after

<?php header ('content-type:text/css');
ob_start("ob_gzhandler"); ?>
<?php ob_flush();?>

Its not a huge edit, since your files are php, they all use includes eg include('menu.php'); for all elements that are identical, the header footer menu etc, so you only need to edit one file to change the calls to *.js *.css to *.js.php *.css.php

Edited by almostbob: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.