In theme.libraries.yml, libraries have a version key. It appears to be optional, but Drupal core libraries (core.libraries.yml) set the version key value as version. What does this keyword mean?

so :

  • Why we use the version keyword ?
  • When should I change the version keyword?
  • You can manually set a version, or if you use version, I believe it picks up your theme's current version number.
    – Jaypan
    Feb 27, 2021 at 18:17

1 Answer 1


Why should I use it?

It is used as an identifier for your libraries. Just like any project/package is tagged in different versions. For eg: jQuery 3.5.1 is slightly different from 3.0.0. The difference could be anything, from API change, new features, bug fixes, etc. Thus we need a way to identify the changes that happened to our library we created. So that we can make some conscious decisions. Another example. Suppose there is a 3rd party js that is having issues with another library of a specific version. So during the install, we can check if the other library has library greater than required.

When should I change its value?

Ideally after every deployment if any change to the library has occurred. So what Drupal does is, it happens the version number to each file in that library when attaching that library to any page. For example: if my library has a css file called custom.css and the version number is say 1.0.0. So, the way it will get attached to the page will be like /path/to/theme/css/custom.css?v=1.0.0. This is so far ok. But ideally on prod environments there are reverse proxies which caches these files. Suppose if we make any new changes to these files and even if we clear the cache, the files will still be served from CDN, thus we also need to make sure if any change has happened on these files, it makes sense to also increase the library version number. Just as you would do with creating a new tag for a new release for any project.

If we give the version as VERSION. Then drupal sets its version = \Drupal::VERSION the current drupal core version.

  • Is there an equivalent "VERSION" value to set the version as the current theme version instead of Drupal core version ?
    – CamelCode
    Jan 12, 2022 at 11:12

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