I just stumbled across this thread and I must say that it had never occurred
to me that you could zip html and have it unzipped at the client - should
read a few more RFCs eh!
Anyway, as excited as a small boy in a big room full of sweets I knocked up
a quick tag. Everyone please feel free to use/ignore/modify/etc.

<!--- cf_gzip by Steve Martin 21/Dec/2000
Utilises cfx_gzip by Michael Peacock, New Media Designs, Inc., which is
based upon public domain code.

Usage: Enclose an entire page in <cf_gzip>yada yada</cf_gzip>
 --->

<cfswitch expression="#ThisTag.Executionmode#">
        <cfcase value="end">
                <!--- Set a couple of defaults. --->
                <!--- attributes.compress allows you to turn off compression for
ebugging  --->
                <cfparam name="attributes.compress" default="1">
                <!--- Compression level --->
                <cfparam name="attributes.level" default="7">
                <!--- Does the browser support gzip --->
                <CFIF listcontainsnocase(cgi.http_accept_encoding,"gzip") and
attributes.compress>
                        <!--- Create a temp filename --->
                        <cfset tmpFile=ExpandPath(CreateUUID() & ".tmp")>
                        <!--- Write the generated content to the file --->
                        <cffile action="WRITE"
                                file="#tmpFile#"
                        output="#ThisTag.GeneratedContent#"
                        addnewline="Yes">
                        <!--- Blank out the generated content --->
                                <cfset ThisTag.GeneratedContent="">
                        <!--- Zip the file (creates a new file with .gz appended)--->
                        <CFX_GZip LEVEL="#attributes.level#" action=GZip 
infile=#tmpFile#>
                        <!--- Delete the original tempfile --->
                        <cffile action="DELETE"
                                file="#tmpFile#">
                        <!--- Serve the gzipped file & delete --->
                        <cfheader name="Content-Encoding" value="gzip">
                        <cfcontent type="text/html"
                   file="#tmpFile#.gz"
                   deletefile="Yes">
                </CFIF>
        </cfcase>
</cfswitch>

ATB Steve Martin



-----Original Message-----
From: Zachary Bedell [mailto:[EMAIL PROTECTED]]
Sent: 20 December 2000 17:55
To: CF-Talk
Subject: RE: [Compress HTML output]


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

Thanks for the reminder on that one!  I was going to do that...  I
even had RFC 2616 on my desk to look up how to do that, and I
completely forgot...

I've actually got some "real work" to do today (darn clients....
always interrupting my fun!), but once I get that taken care of, I'll
integrate the various suggestions on this & see if I can turn it into
a real tag....

Thanks again to everyone for the tips & pointers!

Best regards,
Zac Bedell


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        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