Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:30:09+00:00 2026-06-10T15:30:09+00:00

I’m running Coldfusion8 and jquery/jquery-mobile on the front-end. I’m playing around with an Ajax

  • 0

I’m running Coldfusion8 and jquery/jquery-mobile on the front-end.

I’m playing around with an Ajax powered search engine trying to find the best tradeoff between data-volume and client-side processing time.

Currently my AJAX search returns 40k of (JQM-enhanced markup), which avoids any client-side enhancement. This way I’m getting by without the page stalling for about 2-3 seconds, while JQM enhances all elements in the search results.

What I’m curious is whether I can gzip Ajax responses sent from Coldfusion. If I check the header of my search right now, I’m having this:

    RESPONSE-header
    Connection  Keep-Alive
    Content-Type    text/html; charset=UTF-8
    Date    Sat, 01 Sep 2012 08:47:07 GMT
    Keep-Alive  timeout=5, max=95
    Server  Apache/2.2.21 (Win32) mod_ssl/2.2.21 ...
    Transfer-Encoding   chunked

    REQUEST-header
    Accept  */*
    Accept-Encoding gzip, deflate
    Accept-Language de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
    Connection  keep-alive
    Cookie  CFID=   ; CFTOKEN=   ; resolution=1143
    Host    www.host.com
    Referer http://www.host.com/dev/users/index.cfm

So, my request would accept gzip, deflate, but I’m getting back chunked.

I’m generating the AJAX response in a cfsavecontent (called compressedHTML) and run this to eliminate whitespace

<cfrscipt>
compressedHTML = reReplace(renderedResults, "\>\s+\<", "> <", "ALL");    
compressedHTML = reReplace(compressedHTML, "\s{2,}", chr(13), "ALL");
compressedHTML = reReplace(compressedHTML, "\s{2,}", chr(09), "ALL");
</cfscript>

before sending the compressedHTML in a response object like this:

 {"SUCCESS":true,"DATA":  compressedHTML  }

Question
If I know I’m sending back HTML in my data object via Ajax, is there a way to gzip the response server-side before returning it vs sending chunked? If this is at all possible? If so, can I do this inside my response object or would I have to send back “pure” HTML?

Thanks!

EDIT:
Found this on setting a ‘web.config’ for dynamic compression – doesn’t seem to work

EDIT2:
Found thi snippet and am playing with it, although I’m not sure this will work.

<cfscript>
compressedHTML = reReplace(renderedResults, "\>\s+\<", "> <", "ALL");
compressedHTML = reReplace(compressedHTML, "\s{2,}", chr(13), "ALL");
compressedHTML = reReplace(compressedHTML, "\s{2,}", chr(09), "ALL");

if ( cgi.HTTP_ACCEPT_ENCODING contains "gzip" AND not showRaw ){
    cfheader name="Content-Encoding" value="gzip";

    bos = createObject("java","java.io.ByteArrayOutputStream").init();
    gzipStream = createObject("java","java.util.zip.GZIPOutputStream");
    gzipStream.init(bos);
    gzipStream.write(compressedHTML.getBytes("utf-8"));
    gzipStream.close();
    bos.flush();
    bos.close();
    encoder = createObject("java","sun.misc.
    outStr= encoder.encode(bos.toByteArray());

    compressedHTML = toString(bos.toByteArray());
    } 
</cfscript>

Probably need to try this on the response object and not the compressedTHML variable

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:30:11+00:00Added an answer on June 10, 2026 at 3:30 pm

    Ok. Got it to work.

    I’m using this from the CFLib like so:

    <cfscript>
        // remove whitespace
        compressedHTML = reReplace(renderedResults, "\>\s+\<", "> <", "ALL");
        compressedHTML = reReplace(compressedHTML, "\s{2,}", chr(13), "ALL");
        compressedHTML = reReplace(compressedHTML, "\s{2,}", chr(09), "ALL");
        // gzip
        compressedHTML = gzip(compressedHTML);
    </cfscript>
    <!--- modify header --->
    <cfheader name="Content-Encoding" value="gzip">
    <cfheader name="Content-Length" value="#len(compressedHTML)#" >
    <!--- return cfcontent with reset="no", so I'm not disrupting the Ajax request --->
    <cfcontent reset="no" variable="#compressedHTML#" />
    <cfreturn  />
    

    You also need to make sure to set the return variables for the function which contains the above to binary and the Ajax request must use returntype="html". At least that’s how I got it to work.

    Seems to work nice and my Ajax requests went from 50-60k enhanced markup down to 1-2k. Nice on mobile 🙂

    EDIT:
    If you are having problems with special characters not being displayed correctly, try setting

     <cfheader name="Content-Type" value="text/html; charset=ISO-8859-1">
    

    before returning cfcontent. I don’t know if this is better than UTF-8, but it work for German äöüß, which I was mising in my Ajax response.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.