Results 1 to 4 of 4

Thread: Loading JavaScript files - Best Practices.

  1. #1

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    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?


  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,489

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    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&#37; 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.


  4. #4
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    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
  •  



Click Here to Expand Forum to Full Width