I have a JavaScript library written for my project. It is just that - helper library without configuration. I don't like the idea of empty .module file loading each time. On the other hand, I need it to be versioned and I need to be able to require it in other modules, with version specification. Libraries API looks like a bit of overkill as my script is from the ground written for Drupal and is no way "external" - and using empty .module file would be easier and faster anyway.

So, what's the best practice to include JS-only code?

How to include a JavaScript library, with CSS, in Drupal 7 without using a module? is about JavaScript needed by theme, so it looks similar but is unrelated to my question.

1 Answer 1


A module is really the only appropriate place for something like that; Drupal doesn't provide any way of making a module dependant on a JS library. You can only make a module dependant on another module, so if you want to enforce a dependancy to your JS code you'll have to create a module to contain/reference it.

If you're worried about having an empty module file, don't be...to formalise your library and describe it to the system properly, most likely you should be implementing the core hook_library() anyway. Then your dependant modules can simply call

drupal_add_library('mymodule', 'library');

to add your library. Putting the JS library files themselves into the sites/all/libraries folder, and referring to them from hook_library(), would probably be the best solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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