HTACCESS Wrappers with PHP - Without HTTP compression...
(Page 6 of 9 )
Without HTTP compression it took 5 and a half minutes to download. With the compression, only 2 minutes. Internet Explorer told me the download was going at 20 KB per second, impossible with a dialup connection... but since the file was zipped, I really was downloading 20 KB a second (once the data was decompressed on my end) over a 5 KB per second connection.
Though HTTP compression will work on sounds, video, and images, the space you save is negligible, usually only a few bytes. These sorts of media are already heavily compressed so zipping makes almost no difference. This is why we've told htaccess to only use compression on text and HTML, because it's with human languages like English where a lot of repetition occurs, which means more information can be compressed.
Not all browsers support HTTP compression, but ob_gzhandler() figures out if a browser can support HTTP compression. If the browser doesn't, the original file is displayed, no harm done.
You can get a copy of this sample script at: http://www.jumpx.com/tutorials/wrapper/compress.zip
Both of these scripts I've created for you will work only on static files, files that actually exist such as images or HTML files. If you tried to apply these wrappers as-is to PHP scripts, Perl scripts or even HTML pages that use SSI. If your whole site is run by a single script it's a better idea to hard-code these things right in, anyway.
THE BEST THING SINCE BUBBLE WRAP
This last demonstration of an htaccess wrapper is something that I think most people with content sites have a use for. On the Internet, people steal stuff. Theft of HTML source code is a nuisance, sure, but the lifting of images is more common. Someone likes a logo on your page, or an e-book cover, or a picture of a physical product you're selling, and it becomes theirs to use.
More Web Development Articles
More By 359