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 9122711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:10:00+00:00 2026-06-17T06:10:00+00:00

I have a very large project that has several external javascript files that I

  • 0

I have a very large project that has several external javascript files that I would like to unify in a single large one to optimize server load.

The problem is that many of these scripts have they own (document).ready() events that targets element that are only available on that page.

Unifying everything would put a lot of (different) (document).ready() in a single file and most of them will target elements that are not on the page, is this a problem?

What is the correct way to approach this?

EDIT: Clarification: I mean unify hundreds of javascript file included in they own tag in a single file, so I can minify it.

  • 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-17T06:10:01+00:00Added an answer on June 17, 2026 at 6:10 am

    It sounds to me like you have a different javascript file included on each page and you want to consolidate them together.

    If that is what you are trying to do then the simplest way is to just concatenate all the javascript into a single file. It is fine to have multiple ready calls in the same file. Also jQuery should not error if elements are not present on the page so long as you use jQuery methods to do things (for example $('.element').show() would be fine, but $('.element')[0].style.display = 'block'; would error if the element is not present on that page.

    Putting them all together could have unexpected consequences though if you have things that you only want to apply to specific pages. One way to handle this would be to check which page you are on before attaching specific events. You can do this by checking for specific elements on the page like

    // check if element is present and visible
    if ($('.element').is(':visible')) {
        // now we are on this specific page so let's do everything 
        // specific to this page here
    }
    

    or

    // checks for presence of element
    if ($('.element').length) {
    }
    

    Or you could use an id or other means to differentiate.

    You could now make one $(document).ready(init); call at the bottom of your javascript and the init function could decide what needs to be initialized for that page.

    Hope this helps!

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

Sidebar

Related Questions

I am working on a very large project that has several Visual Studio projects.
I have a very large XML file which has like 40000 data, and when
Has anyone worked at a large company, or on a very large project, that
I have been looking at some frameworks for a very large project like 200+
I have a very large codebase (read: thousands of modules) that has code shared
I have recently started working on a very large C++ project that, after completing
I have a VERY large asp.net application, it has many different .cs files in
I have a very large ASP.NET project that i need to make good with
I have a very large possible data set that I am trying to visualize
I have a very large set of permissions in my application that I represent

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.