In D6, you can put a .js file in your base theme directory and it will automatically be loaded by Drupal.
You can also include a js file via an entry in your theme’s .info file:
However, I recommend the following:
- It should be able to be themed
- Use drupal_add_js() in a theme function
- If in a module, call it with hook_init()
As HTML in a theme function / tpl file, calling your JS with a theme function allows theme developers to modify or override your JS in the theme layer.
Here it is in a module:
- Make sure you check out the drupal_ad_js api for its excellent set of options, such as for controlling caching and placement.
- Creating a namespace for your theme or module.
Share or Comment via Twitter