News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Mod-Deflate directive for .js and .css files?

Started by Chriss Cohn, December 22, 2007, 03:44:53 PM

Previous topic - Next topic

Chriss Cohn

Hi, im using mod-deflate on my server with apache 2.x and i set it to compression-ratio \"1\" and memory-consumption to \"2\" to keep the compressing impact on server very low.
It works really great, but currently i only have set 2 option for mod-deflate in my httpd.conf, one is the above mentioned compression-ratio   memory-consumption, the other is to skip compression on older browsers (found that directive on apache.org), so only html-files get compressed currently.
For the stylsheets-compression i use this:
[i]style.php[/i]
<?php 
ob_start 
(\"ob_gzhandler\");
header(\"Content-type: text/css\");
header(\"Cache-Control: must-revalidate\");
$offset = 60 * 60 ;
$ExpStr = \"Expires: \" . 
gmdate(\"D, d M Y H:i:s\",
time()   
$offset) . \" GMT\";
header(
$ExpStr);
?>

<?php include (\'style.css\'); ?>

I know the codse is not perfect (got it somewhere related to joomla/mambo), as it doesn\'t check if the browser can handle compressed files....

So now, it would be great if there is anyone who knows a directive to activate mod-defalte also for .css and .js files aswell, so i can get rid of the above posted code for my stylesheet and let mod_deflate do all the compression automatically.

Regards, Christian

Chriss Cohn


Sarge

Here are some links (found via Google):
http://www.devside.net/guides/config/compression
"Note that the client browser has to request compression via headers sent on request.
IE will only request compression on .html, but not on .txt nor .css. Mozilla/Firefox can handle all three types."

http://www.howtoforge.com/apache2_mod_deflate#comment-2431
http://www.activecollab.com/forums/topic/1802/

Using PHP instead of mod_deflate:
http://www.fiftyfoureleven.com/weblog/web-development/css/the-definitive-css-gzip-method
http://www.webmasterworld.com/forum83/2514.htm

    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

Chriss Cohn

Thank you very much, this helped my a bit...
This is what i added now to my apache2.conf:
<IfModule mod_deflate.c>
# Use low settings for compression to make sure impact on server is low
DeflateMemLevel 3
DeflateCompressionLevel 2
# compress content with type html, text, css, javascript
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
# Dont encode on following browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

In runs very good, very low impact on server and the overall benefit in smaller and therefor faster loading websites (in my case under 70kb) is unbeatable.
I hope this helps all people who will search for something like this.

Best Regards, Christian


Advertisement: