Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
your CFM code hasn't made it into your question. Can you edit the question to include the code please?
Copy link to clipboard
Copied
<span class="test">
<cfclient>
<cfset variable1 = 10>
<cffunction name="test1">
<cfoutput>#variable1#</cfoutput>
<cfset variable1 = 20>
<cfoutput>#variable1#</cfoutput>
</cffunction>
<cfset test1()>
</cfclient>
</span>
Copy link to clipboard
Copied
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.