Including & optimising javascript & CSS files in Drupal

When including external javascript and CSS files in Drupal it's best practice to do this via your themes .info file. The reason is that the files will then be able to take advantage of the bandwidth optimisation performance settings, ie. they will be aggregated and compressed.

Your .info file can be found at  /sites/all/themes/yourtheme/ 

Just add your files in the below format to your .info file. This assumes that your JS & CSS files are located within /sites/all/themes/yourTheme/js and /sites/all/themes/yourTheme/css  respectively.

; Custom javascript files.
	scripts[] = js/customScripts.js

; Custom css files.
	stylesheets[all][] = css/generalCSS.css
	stylesheets[screen][] = css/screenSpecificCSS.css
	stylesheets[print][] = css/printSpecificCSS.css

Adding JS and CSS in Drupal 8 

Here is a great post on how to go about adding javacript and style sheet files in Drupal 8:
How to add JS and CSS assets to a Drupal 8 theme


Justin Chevallier

Justin Chevallier

Avid Drupal site builder & user for +10 years.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.