0

When an Apache server supports gzip compression, 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

2 Answers 2

3

You want mod_deflate. There's no need to introduce PHP to serve compressed content with Apache.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.