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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:32:30+00:00 2026-05-28T21:32:30+00:00

When drupal_add_js() is called in the module_init() function, will the loaded JS library have

  • 0

When drupal_add_js() is called in the module_init() function, will the loaded JS library have global presence with regards to access to the library by other modules?

Example:

Let’s say that there are two modules – each requires one JS library, and both JS libraries are identically named. The JS libraries exist in their respective module directories. Though both JS libraries are identically named, their contents differ such that each module cannot use the other module’s JS library – doing so will cause the module to fail.

A problem will thus arise IF in fact JS libraries are loaded with global presence following the above-stated method. When the first module is loaded, its JS library will be applied globally across all modules. Next, the second module is loaded and its JS library will be applied globally across all modules. At this stage, both modules are active. Since the JS libraries are identically named, the second module’s JS library would effectively replace the first module’s JS library thus causing the first module to fail.

Thanks!

  • 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-28T21:32:31+00:00Added an answer on May 28, 2026 at 9:32 pm

    The JavaScript code that a module adds with drupal_add_js() is added to the page, and the list of the JavaScript code added to a page is one, and global for every module. This means that the JavaScript code added from a module is visible to every module.

    In fact, that list is contained in a static variable used by drupal_add_js(), and the JavaScript code is added to the page in the page.tpl.php file using the following code:

      <?php print $styles; ?>
      <?php print $scripts; ?>
    

    $scripts is initialized in template_preprocess_page() with the following code, which returns a string containing the HTML to use for the <script> tags basing on the content of that static variable.

      $variables['styles']            = drupal_get_css();
      $variables['scripts']           = drupal_get_js();
    

    If for example, two modules calls the function with drupal_add_js(drupal_get_path('module', 'first_module') . '/jquery_plugin_tree'), and drupal_add_js(drupal_get_path('module', 'second_module') . '/jquery_plugin_tree'), then the page will contain two <script> tags that point to two files, even when the content of the file is the same in both the cases.

    In the case two modules use the same path for the JavaScript file, then there will be just a <script> tag added.

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

Sidebar

Related Questions

so in my THEME_preprocess_page I have drupal_add_js(array('variableName' => 'value'), 'setting'); and in my js
I have a website developed on Drupal. I use a module called collapsiblock (it
How do you add Search form to your Views in Drupal? Do I have
Drupal is very much a Do Everything CMS. There are modules that allow you
Drupal has a very well-architected, jQuery -based autocomplete.js . Usually, you don't have to
In a custom module, I have the following (to add javascript to a particular
I'm trying to get the jquery draggable function to work, particularly the stacking feature,
I've found out that my web pages (mainly index.php, main.html, include.inc) have been injected
When a user gets an Access Denied page, how can you use drupal_add_css to
I'd like to implement a simple AJAX function locally that allows me to autocomplete

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.