Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 593477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:51:00+00:00 2026-05-13T15:51:00+00:00

Most of the javascript I work with is UI code – code that attaches

  • 0

Most of the javascript I work with is UI code – code that attaches additional functionality to the HTML framework of my pages and interacts with various HTML elements.

Overall, I’m in favor of breaking UI code into into modules.

For example, if I have code that attaches handlers to back/next buttons that implements carousel behavior, it makes sense to put that code in a ‘carousel’ module.

The question is, where should I put the boot strap code that runs on page load, and actually decides which modules will be loaded and for what elements?

Should it be in the JS file, and execute as soon as the JS file is included?

Or should it be in a script tag at the top (or bottom) of the HTML file?

Or should there be no particular code, but the JS file should determine which elements to attach handlers, etc to, based on a parent element’s ID/class?

Which method has worked best for you?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:51:01+00:00Added an answer on May 13, 2026 at 3:51 pm

    I usually separate each module in different .js files. Each file/module has its own $(document).ready() (a jQuery bootstrap function) to load properly. Then load that particular file/module by just adding the <script> appropriately.

    This is similar to how plugins work for popular JavaScript libraries/frameworks, all you need to do is include them, and apply behavior.

    EDIT

    For example, the Carousel (carousel.js) model would look something like this:

    (function(){
    
        function bindNext(){...}
        function bindPrev(){...}
    
        // jQuery bootstrap
        $(document).ready(function(){
            bindNext();
            bindPrev();
        });
    
    })();
    

    And maybe another module (foo.js):

    (function(){
    
        function foo(){...}
        function bar(){...}
    
        // jQuery bootstrap
        $(document).ready(function(){
            foo();
            bar();
        });
    
    })();
    

    This way, all I have to do is add those files and the modules will just work. There’s no need of a central location to clobber up all the behaviors of different module, since each modules defines its behavior.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer if($countcomment < 100) { include "commentformonoff.php"; } else { echo… May 16, 2026 at 1:59 pm
  • Editorial Team
    Editorial Team added an answer Once you've checked the username/password and have found that they… May 16, 2026 at 1:59 pm
  • Editorial Team
    Editorial Team added an answer I finally have a working answer for this. I didn't… May 16, 2026 at 1:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Most of my javascript work is done with Firebug and I feel annoying most
I used to work in JavaScript a lot and one thing that really bothered
I have a form on an HTML page with multiple submit buttons that perform
In most of the Programming or scripting language such as PHP or JavaScript, i
I'm using a content-editable iframe to create a syntax-highlighter in javascript and one of
I followed ScottGu's advice on enabling javascript intellisense using a -vsdoc.js file. http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx I
So, I've written a little javascript widget. All a user has to do is
I hear about it a bit in tutorials that I watch, that certain things
For instance, on most blogs you can click on an article and it will
What is the best/most elegant way to abstract out the conversion of units of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.