Created
March 14, 2017 22:15
-
-
Save neokoenig/9f3342b699205188ba702b80012ce8bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!---------------------------- 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