-
May 20th, 2010, 11:21 AM
#1
Thread Starter
Hyperactive Member
Loading JavaScript files - Best Practices.
I guess I should post this in the Asp.Net section, but well....let's see
I got a list of JavaScript files I need to load on forms that validate user input.
Of course I can be "lazy" and just add this once in my Master Page, but as these will not be used on all pages, that's not good.
So right now I have this set of scripts at the bottom of each for that deal with user input, and I figured there could be a better way to deal with this. (Might just look further into combres, but then, I never heard of it)
Code:
<script type="text/javascript" src="<%= Url.JavaScript("validationEngine/jquery.validationEngine-en") %>"></script>
<script type="text/javascript" src="<%= Url.JavaScript("validationEngine/jquery.validationEngine") %>"></script>
<script type="text/javascript" src="<%= Url.JavaScript("jquery.validate") %>"></script>
<script type="text/javascript" src="<%= Url.JavaScript("MicrosoftMvcJQueryValidation") %>"></script>
<script type="text/javascript" src="<%= Url.JavaScript("formfunctions") %>"></script>
Any advice someone learned by dealing with this?
-
May 20th, 2010, 11:32 AM
#2
Re: Loading JavaScript files - Best Practices.
I'd put the ones that you will always use in the master page, then for any of the others, they should only be included on pages where they will be used.
-tg
-
May 20th, 2010, 11:36 AM
#3
Thread Starter
Hyperactive Member
Re: Loading JavaScript files - Best Practices.
That's what I always do as well. Just thought perhaps there's a better way of having to copy/paste a list like that all the time (I guess 60% of this app is forms for logged in users, and there's quite a bit of them)
Just found this post. Sounds like an interesting idea to "declare" groups of scripts and load them like that with a single line.
-
May 20th, 2010, 01:20 PM
#4
Re: Loading JavaScript files - Best Practices.
If you are copying and pasting them all the time then sounds like they should be in the master page. However you could need them for say 5-6 pages in that case for future maintainability I'd add them to a control and include the control on page. This way if one of the files gets changed (In terms of name) you only need to edit it in one place.
Thats my .Net method, not specific to MVC, I like the look of the link you posted and will have a dig into that one a bit more!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|