Hi, all!

i'm working on re-designing the web site for my mother's company,
which was horribly neglected/abused by the previous webmaster, and i
came across an interesting problem...

A part of the refactoring is to use jQuery for parts of the site.
However, since all of the pages use the same site layout template
(which includes the headers/script tags) yet most of the site won't
actually use the JS features, i wanted to make the jQ download as tiny
as possible.

Unfortunately, i don't have admin rights on my server so i cannot
activate mod_gzip/mod_deflate to gzip the stuff on the fly. But here's
an easy workaround...

Create a PHP file called jquery.php:

<?php
  ob_start( 'ob_gzhandler' );
  echo join('',file('jquery-1.1.3.1.pack.js'));
  ob_end_flush();
?>

Now, in the main site layout template i have:

<script type='text/javascript' src='/include/js/jquery.php'></script>

Firebug confirms that the jQ transfer is then 12k, which is tolerable
for my purposes.

It would be only a tiny amount of extra work to integrate the PHP port
of Dean Edwards' packer, such that the packing is done each time
jquery.php is called, but that seems like overkill to me.

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.

Reply via email to