Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFCLIENT JavaScript code optimization technique

New Here ,
Mar 06, 2014 Mar 06, 2014

I wrote this in cfm:

<span class="test">

<cfclient>

     <cfset variable1 = 10>

     <cffunction name="test1">

          <cfoutput>#variable1#</cfoutput>

          <cfset variable1 = 20>

          <cfoutput>#variable1#</cfoutput>

     </cffunction>

     <cfset test1()>

</cfclient>

</span>

and observed that the script tag is generated containing the following code:

globalDivStruct = null;

var _$test_func = function () {

    var self = this;

    var variables = {};

    self.test = function () {

        var localdivstruct = globalDivStruct;

        var __output_var = "";

        localdivstruct.outputvar += variable1;

        variable1 = 20;

        localdivstruct.outputvar += variable1;

        return ""

    };

    self.__init = function () {

        var localdivstruct = globalDivStruct;

        var __output_var = "";

        var tmpVarArray = {};

        variable1 = 10;

        test();

        return ""

    }

};

function __startPage__$test() {

    document.write("\x3cdiv id\x3d'__cfclient_0'\x3e\x3c/div\x3e");

    window.ispgbuild = false;

    var clientDivStruct = {

        divId: "__cfclient_0",

        outputvar: ""

    };

    globalDivStruct = clientDivStruct;

    try {

        _$test = new _$test_func;

        _$test.__init()

    } catch (__eArg) {

        if (__eArg !== "$$$cfclient_abort$$$") throw __eArg;

    }

    __$cf.__flush(clientDivStruct)

}

__startPage__$test();

function test() {

    return _$test.test()

};

As you can see, the code is not optimized. Is there anyway to tell ColdFusion to optimize the code before returning the response? Also, can the optimization engine be specified i.e. closure, uglify etc.

568
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 06, 2014 Mar 06, 2014

your CFM code hasn't made it into your question.  Can you edit the question to include the code please?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 06, 2014 Mar 06, 2014

<span class="test">

<cfclient>

          <cfset variable1 = 10>

          <cffunction name="test1">

                    <cfoutput>#variable1#</cfoutput>

                    <cfset variable1 = 20>

                    <cfoutput>#variable1#</cfoutput>

          </cffunction>

          <cfset test1()>

</cfclient>

</span>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 06, 2014 Mar 06, 2014
LATEST

Posted the CF code. However, my question is simple - the JavaScript code generated when transforming cf code to JS is currently not optimized. Is there anyway I can optimize it. Also, whether I can use any of the optimization libraries like - Closure, Uglify etc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources