When an Apache server supports gzip compr开发者_运维知识库ession, how can from PHP send a CSS file to the client. Is this using .htaccess or with a library? If is a simple .htaccess line, do provide it!
Thanks a lot
You want mod_deflate
. There's no need to introduce PHP to serve compressed content with Apache.
Sometimes there IS a need(reason) to introduce it -- if you really want to use it.
Here's the .htaccess addition you might make:
///////compress text, html, css, xml, & javascript:///////
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
////Or, compress by extension://///
<Files *.html> SetOutputFilter DEFLATE </Files>
//////////////////
If your host has the option disabled on Apache for some reason, then the .htaccess approach will "compress" your site into a 500 error message. 8)
However, if zlib is built into your php, you can use php.ini in your root (or subfolders) to set
zlib.output_compression = 1
and that will compress your php scripts, but no others. If you still really want your css, js, xml (etc) files compressed though you can check this out:
http://www.thewebdevelopmentblog.com/2008/10/tip-speed-up-your-websites-using-gzip-and-merging-files/
it's less than an ideal/site wide solution, but if you have only a few large files that are bugging you... then there you go!
Hope it helps someone! Todd
精彩评论