View Single Post
Old 09-01-2009, 01:37 AM   PM User | #7
orca8767
New Coder

 
Join Date: Aug 2009
Posts: 84
Thanks: 1
Thanked 7 Times in 7 Posts
orca8767 can only hope to improve
if you have any PHP support on a server ANYWHERE, here's a nice little script that will automatically gzip deflate js and css files if the browser supports it:

lib.php:
Code:
<?php
@ob_start('ob_gzhandler');

if(substr($_GET['src'], -3) == '.js')
  $mime = 'text/javascript';
elseif(substr($_GET['src'], -4) == '.css')
  $mime = 'text/css';

header('Content-type:  '. $mime);
readfile($_GET['src']);
?>
What this does is it gets the file path from $_GET['src'] and reads the file after sending appropriate headers, and compresses it along the way, thanks to the second line.

Example usage:
Code:
<script type="text/javascript" src="lib.php?src=path/to/file.js"></script>
Which compresses and outputs the contents of the file at path/to/file.js
orca8767 is offline   Reply With Quote