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

  • Home
  • SEARCH
  • 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 8923267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:04:35+00:00 2026-06-15T07:04:35+00:00

I am using RequireJS and I am creating a own script file for each

  • 0

I am using RequireJS and I am creating a own script file for each page. However I also have some components that are included into some of the pages (server side). Should these pages also get their own script file, or should the necessary javascript be in the containing page? Some of the functionality for the included pages are common to many pages.

  • 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-06-15T07:04:37+00:00Added an answer on June 15, 2026 at 7:04 am

    I think you’d be better off thinking about your javascript as reusable modules rather than page-specific functionality. So, say your page has a search box which initiates an AJAX request, a few date pickers, and a whole bunch of tabs. Each of these should be a module (or if the functionality they provide is complex enough, a few modules). By breaking down your app into small pieces that have very focused aims, you make it easier to test each bit in isolation (automated unit tests) and reuse the functionality elsewhere.

    Now as to how to load your javascript modules, there’s a point where it makes sense to strategically load stuff based on user needs (ex: core.js is loaded by default but search.js isn’t loaded until the user accesses the “search” tab) but you can get pretty far just packaging everything into a single file (require’s r.js tool does this for you) and using the same script file (main.js) on every page.

    When using a single script file, keep in mind that your js will need to work when the target of it’s functionality is not present. jQuery makes this super simple and you almost don’t have to think about it – ex:

    $('#js-foo').on(...) // <-- this doesn't blow up if '#js-foo' isn't on the page. 
    

    I’ve also seen people set a data-attr on the body tag for the page – e.g. data-page=”foo” and key js off of that:

    var page = $('body').data('page');
    if (page === 'foo'){
        component1.setup();
        component2.setup();
    }
    

    In your case, I would try building everything into a single file using RequireJS / AMD-style modules. Each component would get its own module file (mycomponent.js), your main.js would require() all your modules and init things appropriately, and finally you’d configure your r.js build to package everything into a single file when deploying to / running in production.

    If you are interested in exploring this topic more, check out these posts:

    Single Entry Point FTW
    Single Entry Point Redux

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

Sidebar

Related Questions

I am interested in creating my own language using Parrot VM. I have installed
I have a web app built with Dojo 1.7.2, using RequireJS to load individual
Using Require.js and it works pretty solid. However, I'm reading about optimization (http://requirejs.org/docs/optimization.html) using
I'm creating my own recipe box using php/mysql and one part I'm stuck on
I am creating my own implementation of XUL in C++ using the Windows API.
I am creating an app that needs a database. I created it using sqlite
I have been fancying the idea of creating my own search dialog to create
I have an application for Android built using Flex. I need to save some
When creating a window using CreateWindow(...) , which requires the window width and height,
I'm creating a dynamically generated PDF using FPDF. My PDF requires many exactly horizontal/vertical

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.