Libraries also work with external resources, such as assets loaded over a CDN. This is done by providing a URL for the file location along with selected file parameters.
Here is an example to add the FontAwesome font icon library from the BootstrapCDN provided by MaxCDN:
mytheme.fontawesome:
remote: http://fontawesome.io/
version: 4.4.0
license:
name: SIL OFL 1.1
url: http://fontawesome.io/license/
gpl-compatible: true
css:
base:
https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css: { type: external, minified: true }
Remote libraries require additional metainformation to work properly:
remote: http://fontawesome.io/
The remote key describes the library as using external resources. While this key is not validated beyond its existence, it is best to define it with the external resource's primary website:
version: 4.4.0
Like all libraries, a version is required. This should match the version of the external resource being added:
license:
name: SIL OFL 1.1
url: http://fontawesome.io/license/
gpl-compatible: true
If a library defines the remote key, it also needs to define the license key. This defines the license name, the URL for the license, and checks whether it is GPL-compatible. If this key is not provided, a \Drupal\Core\Asset\Extension\LibraryDefinitionMissingLicenseException will be thrown:
css:
base:
https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css: { type: external, minified: true }
Finally, specific external resources are added as normal. Instead of providing a relative file path, the external URL is provided.