Utility Function: RequireScript()

I'm not too happy with with this implementation, but I think it works out fairly well. Note that it uses the two functions in the related posts.

<cffunction name="RequireScript" access="public" output="false" returntype="void">
<cfargument name="script" type="string" required="true" />

<cfif NOT StructKeyExists(request, "__requirescript")>
        <cfset request["__requirescript"] = ArrayNew(1) />
    </cfif>
    <cfif NOT ArrayFind(request["__requirescript"], arguments.script)>
        <cfset ArrayAppend(request["__requirescript"], arguments.script) />
        <cfset IncludeScript(arguments.script) />
    </cfif>
    
<cfreturn />
</cffunction>

 

Related Blog Entries

Comments are not allowed for this entry.
Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.