I was wondering what’s best practice for a javascript file’s location that is view-specific.
Some of my views have 1700+ lines of code, 70% of it being javascript, so I’m putting them into a .js file to take advantage of bundling/minifying.
I know core script files (eg. jquery) typically go into the root /Scripts folder, but there are a LOT of views that i need to do this to (50+), so I’m wondering if I should put them in their respective view folders (eg: /Views/Account/ViewName.js) or should i dump them all into the /Scripts folder at the root.
In my practices, I’ve basically made the following static assets structure:
And using some controller logic, I add a file per controller to
/public/javascript/controllersso that way my controller specific code is all bundled together.You could just as easily rig it to be per model, and then have object oriented methods in your js files like this:
doing it this way would mean that you’d need a parent javascript file that basically finds the proper javascript model object (i.e.
myModel), then controller method (pageA) and then calls that function.Anything more complex than that really starts bringing you into the territory of you needing a javascript assets manager like require.js