The best Drupal news and links delivered to your inbox every week

Asset Management In Drupal 8 - Sam Boyer - DrupalCon Portland 2013

Check out the DrupalCon Portland notes hub page for notes from other sessions at DrupalCon Portland.

Session: Asset Management In Drupal 8

Day - Time Slot: Tuesday, May 21 - 10:15am–11:15am

Presenter: Sam Boyer

Twitter: sdboyer sdboyer
Slides: Slides

session page



  • Sam is not a frontend dev

Asset Management

  • What are assets in the context of this talk? Stylesheets, and JS. Not images.
  • How do you declare them. Can you write in Coffeescript, LESS or SASS easily in Drupal. Not a fun process
  • How does the browser get them and how fast? Frontend performance

How to declare assets Now

  • Theme
  • Libraries
  • attached

  • drupal_add_css() & drupal_add_js()
  • These are going away
  • Meta-properties like “scope” and “group” and “browser”

What Sucks about the Status Quo

  • Each asset has a explicit weight
  • Global functions are death to caching.
  • Support for SASS and other preprocessors is awkward at best

Assetic PHP Library

  • Assetic is a PHP library for asset management
  • Ships with Symfony
  • Assets are files, glob, strings and http
  • local
  • remote
  • string
  • glob (pass * and it will combine all of the files in a directory into one asset)
  • Filters for CoffeeScript, Compass/SASS CSS minification etc.
  • Filters are not PHP.
  • Should work with Drupal 8 without installing extra software on your server. Binaries may be shipped with Core and should provide the functionality.

Assetic in Drupal

  • Drupal assets
  • Asset bags. Have a lot of assets to declare? Drop them into a bag. Bags are a way to pass around assets through the Drupal system
  • Dependancies work much better than weights. If a js file depends on jQuery it will not be loaded before jQuery. This works similarly to Require.js.

Options for Drupal 8

  • Option 1: #attached
  • Option 2: Attached + Assetic
  • Option 3: SCOTCH


  • Question: Why not just compile with native tools in development(why use the Assetic filters)? Then in prod just use a build script to deploy to production.
  • One Answer: Having the compiling(filters) tools baked in helps non-hardcore Drupal developers. One less thing learn. Also, you do not have to use filters

What are you waiting for? Subscribe already.

Published by Bob Kepford

Powered by Drupal