-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> compression is a web server issue NOT CF. 

That's true, but it doesn't mean you can't do it in CF...

Below is a custom tag that will do just that, provided you have
CFX_GZip installed (freely downloadable from the tag gallery).

I'm not sure whether the savings in bandwidth is worth the additional
processor power (anyone wanna run tests?), but it's still nifty...

One place this would really be a savings:  If you already use
CFCACHE, you should be able to modify the CFCache tag to also do
compression before it saves a file.  That way you only need to
compress the file once, and you get the processor savings of CFCache
AND the bandwidth savings of compression.

I'll probably post this tag to the tag gallery once I beat on it for
a little longer.  In the meantime, enjoy...

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>
Comment: Please use PGP!

iQA/AwUBOj5/Z6vhLS1aWPxeEQKSRwCg+iRBf/fA8Y72IbopUMF0kM6NEkkAnj+k
wwQDQrb5RkIfgaFn1TRaW8Ub
=4/Jb
-----END PGP SIGNATURE-----

<!--- CF_GZipPage
        Make sure this tag surrounds the ENTIRE page.  It will GZIP the
GeneratedContent using
        CFX_GZip and modify the browser headers so that the browser can
decode it.

        Anything that falls outside of the start and end tag for this tag
will be ignored and never
        seen by the client.
        
        Parameters (All are optional):
                Level:  The GZip Compression Level, 0 is lowest compression
(biggest size, least processor usage),
                        9 is highest compression (smallest size, greatest
processor usage)
                Unique: If you'd prefer something more unique than a second
random number for tempfiles, specify it here
                        Make sure the contents of the variable are all valid
in a filename.
                        
        CopyLeft 2000 Zachary Bedell <[EMAIL PROTECTED]>
        
        You may use this code as you wish provided I retain credit in the
comments or elsewhere.
        
        No Warrenty.  If it breaks, you get to keep both pieces....
 -ZSB 18-Dec-2000
--->
<cfif ThisTag.ExecutionMode EQ "END">
        <!--- Sane defaults: --->
        <cfparam name="Attributes.Level" default="9">
        <cfparam name="Attributes.Unique" default="#RandRange(1,10000000)#">
        
        <!--- Setup path & filename for tempfiles: --->
        <cfset RawHTMLFile =
"c:\Temp\Compress\#Cgi.Script_Name#_#Attributes.Unique#_#RandRange(1,1000000
)#.out">
        <cfset GZippedFile =
"c:\Temp\Compress#Cgi.Script_Name#_#Attributes.Unique#_#RandRange(1,1000000)
#.in">

        <!--- Grab the generated content and write it out to a tempfile.
--->
        <cfset Content = Trim(ThisTag.GeneratedContent)>        
        <cffile action="WRITE" file="#RawHTMLFile#" output="#Content#">
        
        <!--- Compress the tempfile to another tempfile --->
        <cfx_GZip action="GZIP" InFile="#RawHTMLFile#"
OutFile="#GZippedFile#" level="#Attributes.Level#">
        <cffile action="delete" file="#RawHTMLFile#">
        
        <!--- Setup the headers and write the mess back out to the client w/
CFCONTENT --->
        <cfset ThisTag.GeneratedContent = "">
        <cfheader name="Content-Encoding" value="gzip">
        <cfcontent file="#GZippedFile#" deletefile="Yes" type="text/html">
</cfif>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to