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

Okay...  I think the tag is done.  I made a few more changes (see
below).

I also figured out how to automagically compress all the pages in
your site w/ one little change.

Here's what I did find:
In the Application.cfm, I put this code:

<CF_GZipPage>
<Cfinclude template="/RootMapping#CGI.Script_Name#">
<cfinclude template="OnRequestEnd.cfm">
</CF_GZipPage>
<cfabort>

Note that you could omit the OnRequestEnd line if you don't use that
file OR you could put it into a try block if you're not sure
they're'll be an OnRequestEnd like:
<cftry><cfinclude template="OnRequestEnd.cfm"><cfcatch
type="MissingInclude"></cfcatch></cftry>

Also note that the above, if dropped at the end of your
application.cfm would ignore any & all output that was actually
generated by your app.cfm.  That's what I wanted in my case.  If
you're outputting stuff in your app.cfm that you need, then you
should do something like:

<CF_GZipPage>
<!--- All your app.cfm stuff here. --->
<Cfinclude template="/RootMapping#CGI.Script_Name#">
<cfinclude template="OnRequestEnd.cfm">
</CF_GZipPage>
<cfabort>


We get anywhere from 2 to 10 times compression, and our customers are
already commenting on the speed increase.  The system's processors
are of course working a little harder now, but that means they're
floating at 10% instead of at 4%.  Whoopee!



Here's the tag for people's perusal.  If you find any glaring errors
or have general suggestions, please share them with me.  If I don't
hear anything, I'll post this in the tag gallery some time next week.

Best regards,
Zac Bedell

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

iQA/AwUBOkObpqvhLS1aWPxeEQJAcwCaAlXKaaZrAK4UDYzvMZ/pVaT/wTUAoOuF
sdj1jvSQDab6aH6Q4TV9xQHZ
=3LEC
-----END PGP SIGNATURE-----

GZipPage.cfm: (This will probably be looped by your mail reader/server.)
=-=-=-=-=-=-=
<!--- CF_GZipPage  --  Let's call this Version 1.0...   
        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)
                Directory: The temporary directory to use for compression.
Two files will be created here for each
                        request.  This directory must exist or the tag will
error.
                        
        CopyLeft 2000 Zachary Bedell <[EMAIL PROTECTED]>
        
        Special thanks to:
                Orlando Correa <[EMAIL PROTECTED]> for suggesting
the Directory attribute and for code to check
                        the Accept-Encoding header.
                Peter Stolz <[EMAIL PROTECTED]> for reminding me that
the Accept-Encoding header exists...
                All the folks on CF-Talk who took the time to read these
posts & test out the tag.               
        
        You may use this code as you wish, no strings attached.
        
        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.Directory" default="c:\temp">
        <cfparam name="Attributes.ShowDebugging" default="false">

        <cfif ListContainsNoCase(CGI.HTTP_Accept_Encoding, "gzip") AND
Attributes.Level GT 0 AND Attributes.Level LTE 9>
                <!--- 
                        If this browser can't handle GZIP encoding, then
there's no point in doing anything... 
                        If the GZIP level is 0 that means no compression, so
let's not waste our time.  
                        Also, if it's greater than 9, we'd have an error, so
just get on with things... 
                --->
                <cfset Directory = Attributes.Directory>
                <cfif Right(Directory, 1) NEQ "\"><cfset Directory =
Directory & "\"></cfif>
                
                <!--- Setup path & filename for tempfiles: --->
                <cfset UniqueFilePath = "#Directory##CreateUUID()#">
                <cfset RawHTMLFile = "#UniqueFilePath#.htm">
                <cfset GZippedFile = "#UniqueFilePath#.gz">
        
                <!--- Grab the generated content and write it out to a
tempfile. --->
                <cfset Content = Trim(ThisTag.GeneratedContent)>
                <cfif Attributes.ShowDebugging>
                        <cfset DebugText = "#Chr(13)##Chr(10)#<!-- Page
Compressed by CF_GZipPage. Original Size: #Len(Content)#-->">
                        <Cfset Content = Content & DebugText>
                </cfif>
                <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>
</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