Posted By

dave333 on 08/06/08


Tagged

javascript php gzip compression Requests


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

not_skeletor
luman
liuran
bryandease
huynguye
Kurt
bodito


GZip All your JS files in to one file


 / Published in: PHP
 

Runs through a folder of JS files, and output them as one file (to save on HTTP requests) and GZips the output to speed up the download more.

  1. ob_start('ob_gzhandler');
  2. header('Content-Type: text/javascript');
  3. $off = 15768000; //Number of seconds for the browser to cache the output
  4. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $off) . ' GMT');
  5. header('Cache-Control: Public');
  6. header('Pragma: Public');
  7.  
  8. $handle = opendir(dirname(__FILE__)); //Assumes the PHP file is in the same folder as the JS files
  9.  
  10. while (false !== ($f = readdir($handle))) {
  11. if(substr($f,-3) == '.js'){
  12. readfile($f);
  13. echo "\n\n";
  14. }
  15. }

Report this snippet  

You need to login to post a comment.