I recently came across a really good post on StackOverflow, but it seems to have been deleted, so I’m going to repost it for those of you who may need it.
To make it so that I’ve only got one copy of a function, I did the following:
- Created a new script file in the Scripts folder. (In this case, I’ve called it “pylonCommon.js”)
- In the App_Start folder, in BundleConfig.cs, add a new bundle. It’ll look something like the following:
- In _Layout.cshtml, you’ll now need to pull in the bundle. This is done with the following, placed near the top of the file (just below the other @Scripts.Render statements:
That being said, to enable bundling and minification, you’ll need to follow the steps listed here: http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification