Results 1 to 1 of 1

Thread: Gzip All CF pages

  1. #1
    ViperLord Guest

    Default Gzip All CF pages

    Here's a method for enabling gzip compression on pages served through your application.cfc

    Expanding on

    <cffunction name="onRequestEnd" returnType="void" output="true">
    	<cfargument name="thePage" type="string" required="true">
    	<cfif cgi.HTTP_ACCEPT_ENCODING contains "gzip">
             		pageOut = getPageContext().getCFOutput().getString();
             		fileOut = createobject("java", "").init();
             		out = createobject("java","").init(fileOut);
             		out.write(variables.pageOut.getBytes(), 0, len(variables.pageOut.getBytes()));
    	  	<cfheader name="Content-Encoding" value="gzip">
    	  	<cfcontent type="text/html" reset="true" variable="#fileOut.toByteArray()#">
    This will compress pages before they are sent to the browser (if the browser supports it), resulting in smaller/faster pages.

    If you are using CF to serve up images, XLS, other or binary filetypes, you will probably want to add something to the cfif to prevent gzip.

    Support also suggested:, but I think my variation may be cleaner.
    Last edited by ViperLord; August 19th, 2009 at 06:59 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts