Posted By

relaxasaurus on 12/04/08


Tagged


Versions (?)

Who likes this?

13 people have marked this snippet as a favorite

ginoplusio
VaiT
rickfu
jeremyhcobb
bryandease
nb109
vali29
johnskopa
Adam42
dimispaceman
metthyn
wirenaught
sbcjr


Compress Javascript or CSS files in gzip


 / Published in: PHP
 

Add this code to the top of the JS or CSS file in <?php ?> tags. Change it's extension to PHP. When linking external files in the <head> tags remember to use .php instead of .js or .css

To further decrease the file size, compress larger JS/CSS files with the YUI compressor: http://www.refresh-sf.com/yui/

Comparison: http://www.julienlecomte.net/blog/2007/08/13/

  1. ob_start ("ob_gzhandler");
  2. header("Content-type: text/javascript; charset: UTF-8");
  3. header("Cache-Control: must-revalidate");
  4. $offset = 60 * 60 ;
  5. $ExpStr = "Expires: " .
  6. gmdate("D, d M Y H:i:s",
  7. time() + $offset) . " GMT";
  8. header($ExpStr);

Report this snippet  

You need to login to post a comment.