I have to agree with @Domenic's answer here. @Nishchay Sharma is way off.
The only thing I'll add is if you want to do this on a per-script basis rather than configuring your entire server to compress everything, it's trivial to accomplish your goal by using PHP's gzencode() function coupled with a header call:
http://www.php.net/manual/en/function.gzencode.php
For instance, let's say you are retrieving a huge set of data via an Ajax call to a PHP page. You could configure the PHP page to use gzencode as follows:
<?php
$someBigString = gzencode('blahblah...blah');
header("Content-type: text/javascript");
header('Content-Encoding: gzip');
echo $someBigString;
?>
(This is overly simplified, of course, but I'm keeping it simple.)
Your JS Ajax call will pull the data down, see the gzip header, and decompress it automagically. I personally use this technique for very large geo-coordinate data sets for Google Maps that can be many megabytes in size when uncompressed. It couldn't be easier!