Jump to content

Static compression for CCC


sors

Recommended Posts

This modification for combined js and css files statical compression. The source files are compressed with maximum compression and replace original files in cache directory with source files are located in cache directory with nogzip extension.

.htaccess rules give the compressed files with gzip headers and none compressed for old browser.

In classes\Tools.php replace

file_put_contents($compressed_js_path, $content);
chmod($compressed_js_path, 0777);


With

file_put_contents($compressed_js_path.'.nogzip', $content);
chmod($compressed_js_path.'.nogzip', 0777);

$c = @gzencode($content, 9, FORCE_GZIP);
if (!empty($c)) {
   file_put_contents($compressed_js_path, $c);
   chmod($compressed_js_path, 0777);
}


replace

file_put_contents($cache_filename, $content);
chmod($cache_filename, 0777);


With

file_put_contents($cache_filename.'.nogzip', $content);
chmod($cache_filename.'.nogzip', 0777);

$c = @gzencode($content, 9, FORCE_GZIP);
if (!empty($c)) {
   file_put_contents($cache_filename, $c);
   chmod($cache_filename, 0777);
}


Add to .htaccess


   RewriteEngine On
#redirect for Konqueror and old browsers
   RewriteCond %{HTTP:Accept-encoding} !gzip [OR]
   RewriteCond %{HTTP_USER_AGENT} Konqueror
   RewriteRule ^(.*)\.(css|js)$ $1.nogzip.$2 [QSA,L]



   Header append Vary User-Agent
#set Content-Encoding for css/js files

   Header set Content-Encoding: gzip
   Header set Cache-control: private

#reset Content-Encoding if nogzip

   Header unset Content-Encoding


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...