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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:27:10+00:00 2026-06-16T05:27:10+00:00

I have site which is using a few JavaScript/jQuery plugins, I then have a

  • 0

I have site which is using a few JavaScript/jQuery plugins, I then have a default.js file which uses the plugin functionality for each of the different pages.

E.g. some plugins I have include:

  • a custom scrollbar plugin
  • a slideshow plugin
  • a cookie plugin
  • etc.

Then in the default.js file, I’ll do something as follows (pseudocode):

var scrolling = findScrollbarDiv;
scrolling.ScrollFunction({ options });

(and then the same for the slideshow + other plugins I have)

However, if there is a plage where findScrollbarDiv returns null, I get an error something like the following:

ScrollFunction is not a function

This is not because the elements are returning null, but because I haven’t included the plugin file for this page. My reasoning behind this is that I don’t want to include every file on every page (even if it’s not needed) as this could cause unnecessary HTTP requests (especially on the homepage, which only needs one plugin)

This error in turn messes up the rest of the JavaScript.

What is the best way to overcome this? Should I just include every plugin file on every page regardless of whether it is needed or not? Or is there some JavaScript like the following that I can use:

var scrolling = findScrollbarDiv;
if(scrolling != null) {
    scrolling.ScrollFunction({ options });
}

(this feels a bit clunky to me, but if this is the best solution let me know)

Or is using one default js file to launch all plugins a bad idea?

  • 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-16T05:27:12+00:00Added an answer on June 16, 2026 at 5:27 am

    If you’re using the same header file and you don’t mind having the file included, you can always check if the element exists before attaching an event to it.

    Heres an example:

    if(jQuery('#someElement').length > 0){
        jQuery('#someElement').ScrollFunction({ options });
    }
    

    Either that, or have a JavaScript file for each function.

    So you’d have one for the gallery and one for the cookies etc.. And include only the ones necessary for each page.

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

Sidebar

Related Questions

I have a site which I want to download using Unix wget . If
i have watched a site which has taught iphone application using dashcode.it says dashcode
I have a web site with an API which publishes the information using JSON.
I have an ASP.Net site, in which I am using a ListView with a
I'm developing a site using the CakePHP framework. I have a form which shows
I have site which uses $(selector).load(path) function in more than 300 pages. Now my
I have a site which relies heavily on javaScript. I created a mirror site,
I'm getting more into jQuery and so have set up a HTML/Javascript/CSS base site
I have a web site which needs to be using https connection for pretty
I have a site which needs to be fully self-contained in the browser window,

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.