I've two different techniques inside my disposal:
- use mod_deflate to create Apache compress JS/CSS files inside a given directory through htaccess
- use doctor_start('gzhandler') to compress personal files and give it back towards the browser using the correct headers.
The issues with method 1 are that does not all browsers support mod_deflate, and that i have no idea crafting the htaccess file to become wise enough to regulate with this.
The issue with method 2 is the fact that there's no definitive answer about how exactly to inform if your browser supports a gzipped script, or stylesheet, which whether it does what mime-type should be given because the content enter in the header.
I want top tips. First, which technique is more globally recognized by browsers? Second, how do you decay using either approach to supply the uncompressed backup script? Third, would
mod_deflate and php's gzhandler both derive from zlib, so for the reason that sense there's little impact on a browser the way the submissions are being compressed.
in reaction for your main objective, you are able to set module specific .htaccess info such as this:
<IfModule mod_deflate.c> # stuff </IfModule>
in reaction for your second concern, you are able to identify for browser support in PHP:
if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') ) doctor_start('ob_gzhandler') header("Content-Encoding: gzip") // etc...
here's some untested .htaccess which should have the ability to handle settlement of compressed versus uncompressed .js files: (source)
The easiest method to achieve to your server to aid inline gzip. You'd go ahead and take ".gz" off both script tag's src attribute and keep file around the server uncompressed. When the client supported it, the server would instantly send the script like a gzip encoded result. This may cost your server additional CPU, however the file will get compressed for individuals clients that support it, while older clients get the broadened version.
Take a look at mod_deflate for apache2. mod_gzip may be the equivalent for Apache 1.x.
When the browser is correctly setting it's
Accept-Encoding header, you need to have the ability to know if the browser supports gzip: