2

I'm looking to include a few JS files (some libraries, others are custom modules with dependencies on libraries). Originally I had all JS files added through our .info file, and while I could control the order of the files manually my moving them up and down, that would result in all the JS files loading on every page.

Is it a better idea to add JS files through template.php in the template_preprocess_html function? For each JS file I can attach a group property (one of the constants of JS_Library, JS_DEFAULT, or JS_THEME) to control the ordering, and also control which pages need to load which files.

Thoughts?

  • Assuming your question as How to include js page specifically. Answer can be drupal_add_js() is what you are looking for. for example – arpitr Sep 24 '13 at 19:12
  • 1
    @arpitr The question is really what is the best place to add .js files that should be included on every page, but should be included in the JS_LIBRARY or JS_THEME group. It seems the 2 options are to add them to the .info file and then change their group in hook_js_alter() or to add all of them in template_preprocess_html(), which would certainly work but I'm not sure if it has drawbacks. – Charlie Schliesser Sep 24 '13 at 19:17
0

You can try JS injector module which provides an UI for that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.