Skip to content

Instantly share code, notes, and snippets.

@neokoenig
Created March 14, 2017 22:15
Show Gist options
  • Save neokoenig/9f3342b699205188ba702b80012ce8bb to your computer and use it in GitHub Desktop.
Save neokoenig/9f3342b699205188ba702b80012ce8bb to your computer and use it in GitHub Desktop.
<!---------------------------- In /events/onrequeststart.cfm ------------------------>
<cfscript>
// Setup placeholder for JS
request.js={};
</cfscript>
<!---------------------------- In your view File ------------------------>
<cfoutput>
Stuff
</cfoutput>
<cfsavecontent variable="request.js.mycoolthing">
<script>
$(document).ready(function(){
// your JS
}
</script>
</cfsavecontent>
<!---------------------------- In your layout ------------------------>
<!--- Scripts in footer
I might use grunt.js to build my "main" JS, inc. jQuery/Bootstrap etc
We can even load a different version depending on environment
-->
<cfif application.wheels.environment EQ "production">
#javascriptIncludeTag("mysite.min")#
<cfelse>
#javascriptIncludeTag("mysite")#
</cfif>
<!--
Ouput Dynamic Javascript Set in Page after main JS
All we're doing is looking for struct keys within request.js and looping them out
--->
<cfif structkeyexists(request, "js")>
<cfloop list="#structKeyList(request.js)#" index="key">
<cfoutput>#request.js[key]#</cfoutput>
</cfloop>
</cfif>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment