|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Enthusiast
![]() Join Date: Jul 2004
Location: Florida
Posts: 48
|
Is there any way to configure PHP to compress not only PHP output but Javascripts files (.js) and CSS files (.css) that are referred into the PHP script?
I have enabled "zlib.output_compression on" and "zlib.output_compression_level 3", but I afraid that doesn't affect to JS and CSS file formats. Thank you very much in advance. Mapg |
|
|
|
|
|
#2 |
|
SitePoint Member
Join Date: Jun 2003
Location: Canada
Posts: 14
|
|
|
|
|
|
|
#3 |
|
SitePoint Enthusiast
![]() Join Date: Jul 2004
Location: Florida
Posts: 48
|
I have added AddType application/x-httpd-php .php .css .js
and works ... At least I see these files (.css and .js) as gzipped at ... http://leknor.com/code/gziped.php So I am not sure if it's necessary to add some kind of header to css or js files like as follow ... PHP Code:
php_value auto_prepend_file gzip-css.php (as noted in the link that you provided) Is it enough if I saw gzipped my css files at http://leknor.com/code/gziped.php? Thanks Mapg |
|
|
|
|
|
#4 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2004
Posts: 1,647
|
congratulation for the site and the script!
really impressive! nice job ![]() |
|
|
|
|
|
#5 |
|
SitePoint Member
Join Date: Jun 2003
Location: Canada
Posts: 14
|
From:
http://www.fiftyfoureleven.com/sandb...s-gzip-method/ 1. You save this snippet as gzip-css.php: Code:
<?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);
?>
Code:
AddHandler application/x-httpd-php .css php_value auto_prepend_file gzip-css.php Since you probably don't want to do that, and you want your JS gzipped you should do the following: Keep your htaccess rule of: Code:
AddType application/x-httpd-php .php .css .js Code:
<?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);
?>
Code:
<?php
ob_start ("ob_gzhandler");
header("Content-type: text/javascript");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>
|
|
|
|
|
|
#6 |
|
SitePoint Enthusiast
![]() Join Date: Jul 2004
Location: Florida
Posts: 48
|
Thank you very much for your reply.
Seems that configuring PHP with ... Code:
zlib.output_compression on Code:
php_flag zlib.output_compression on ... it's not necessary to add "ob_gzhandler" in every css or js file. After that, Code:
AddType application/x-httpd-php .php .css .js I am agree with you that ... Code:
header("Content-type: text/css");
Code:
header("Content-type: text/javascript");
But ... Code:
* snip *
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
* snip *
I also added ... Code:
zlib.output_compression_level 3 ... or if you prefer a htaccess file ... Code:
php_value zlib.output_compression_level 3 http://leknor.com/code/gziped.php Best Regards, Mapg |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 07:29.










Linear Mode
