MyBB Internal: One or more warnings occured. Please contact your administrator for assistance.
WebPagetest Forums - Coldfusion Keep-Alives and GZip Tutorial

WebPagetest Forums

Full Version: Coldfusion Keep-Alives and GZip Tutorial
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey there,

It took me a few days to figure out how to GZIP coldfusion (.cfm) files while making sure keep-alives were enabled.

I across the following article describing how to make HTTP KeepAlives and Coldfusion Servers work together:

The line that lead me to a solution was packets need to contain a content-length value. So here is my solution to getting coldfusion (.cfm) files GZIPPED and Keep-Alives enabled:

function HtmlCompressFormat(sInput)
    var level = 2;
    if( arrayLen( arguments ) GTE 2 AND isNumeric(arguments[2]))
        level = arguments[2];

    sInput = trim(sInput);
        case "3":
            sInput = reReplace( sInput, "[[:space:]]{2,}", " ", "all" );
            sInput = replace( sInput, "> <", "><", "all" );
            sInput = reReplace( sInput, "<!--[^>]+>", "", "all" );
        case "2":
            sInput = reReplace( sInput, "[[:space:]]{2,}", chr( 13 ), "all" );
        case "1":
            sInput = reReplace( sInput, "(" & chr( 10 ) & "|" & chr( 13 ) & ")+[[:space:]]{2,}", chr( 13 ), "all" );
    return sInput;

<cfsavecontent variable = "raw">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>



<cfif cgi.HTTP_ACCEPT_ENCODING contains "gzip">
  <cfset raw = #htmlCompressFormat(raw, 2)#>
  fileOut = createobject("java", "").init();
  out = createobject("java","").init(fileOut);
  out.write(raw.getBytes(), 0, len(raw.getBytes()));
  <cfheader name="Content-Encoding" value="gzip">
  <cfheader name="Content-Length" value="#len(fileOut.toByteArray())#">
  <cfcontent type="text/html; charset=utf-8" reset="true" variable="#fileOut.toByteArray()#">  
  <cfoutput>#htmlCompressFormat(raw, 2)#</cfoutput>

I hope this comes in handy for other coldfusion developers working on page speed issues.

Travis Walters
Thx for the tut, mate Smile

generic viagra soft
buy acomplia
great tut! helped me a lot Smile thanks.
Hey Guys,

Something else I recommend having in my script:

<cfheader name="Expires" value="#GetHttpTimeString(DateAdd('m', 1, Now()))#">

This helps caching a bit. You can set the time for whatever you want as long as it follows the produced output in the line above.

Travis Walters
Reference URL's