On Aug 15, 11:08 am, Stephan Beal <[EMAIL PROTECTED]> wrote: ... > This approach could just as easily be used to combine all required JS > scripts on the fly (just be sure to insert a ';' after each one to > accommodate scripts which don't have them), then gzip them, to help > reduce the overall download overhead.
A small follow-up: After doing some reading, it turns out that PHP has a more efficient manner of reading text files (which uses mem-mapping to avoid extra string copying), called file_get_contents(). So here's a slightly expanded version which uses that function (using fopen() and friends would probably be optimal, though) and takes an array of JS files, effectively concatenating the results into one script: <?php ob_start( 'ob_gzhandler' ); // optional: header( "Expires: Fri, 27 Aug 2010 12:12:12 GMT" ); foreach( array( 'jquery-1.1.3.1.yuimin.js', 'jquery.cycle.all.yuimin.js' ) as $fn ) { echo file_get_contents($fn); echo ";\n"; // accommodate scripts which are missing a trailing semicolon } ob_end_flush(); ?> Happy hacking!