gzip without mod_gzip nor mod_deflate and pre gzipped files
My hosting company does not support mod_gzip nor mod_deflate.
I must gzip .js and css files
I have pre-compressed the files.
I use Joomla, and to add scripts to the document, I must use a PHP file that serves the .js.gz files whenever the encoding is accepted by the user (example of PHP joomla code):
$document = &JFactory::getDocument();
$document->addScript($jQueryPath);
I added the directive below to .htaccess; however, the browsers are not decompressing the .js.gz files
# Add some gzip to the bunch
AddEncoding x-gzip .gz
<FilesMatch \.js.gz$>
ForceType text/javascript
Header set Content-Encoding "gzip"
</FilesMatch>
<FilesMatch \.css.gz$>
ForceType text/css
Header set Content-Encoding "gzip"
</FilesMatch>
RewriteCond %{REQ开发者_如何学GoUEST_FILENAME} ^.+\.(js|css)$ [NC]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.+)$ $1.gz [L,QSA,NC,NS]
Could anyone help on how to gzip under the described conditions?
Thank you,
Most php installations come with the Zlib extension which lets you manipulate gzip files.
Take a look at these php manual pages to accomplish what you asked for:
http://www.php.net/manual/en/function.gzcompress.php
http://www.php.net/manual/en/function.gzdeflate.php
http://www.php.net/manual/en/function.gzencode.php
you can use the $_SERVER superglobal to check the Accept Encoding Header:
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate'))
{
// DO STUFF HERE
}
elseif (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
{
// DO STUFF HERE
}
精彩评论