Search code examples
phpdrupaldrupal-7drupal-theming

Where is it best advised to include JavaScript and CSS files in Drupal?


Where is it best advised to include JavaScript and CSS files, in the case you have a theme and a sub-theme? Does it have the same effect when you use those files from a .info file, a template file, or a module?


Solution

  • For JavaScript files, the files are being grouped by where they are called from. Below is the order in which they are called.

    1. Libraries: Libraries, settings, or jQuery plugins
    2. Modules: Javascript files added by modules
    3. Themes: Javascript files added by theme (like in .info files)

    See the description for $options given in drupal_add_js().

    For CSS files, there are three groups too.

    1. System layer CSS files (e.g. modules/system/system.menus.css and modules/system/system.theme.css)
    2. CSS files added by modules
    3. CSS files added by themes

    See the description for $options in drupal_add_css().