Origin Pull CDN in Drupal 8

Origin Pull CDN in Drupal 8 Origin pull CDN is a type of CDN where you don't have to upload files to the CDN server instead CDN does it for you. You only rewrite URLs to point to the CDN. When asked for a specific file, the CDN will first go to the original server, pull the file, cache and serve it.

Origin pull CDNs are easy to set up. However, it’s less flexible and can create redundant traffic as files are re-queried before they have been changed. Also it could be slow when files first loaded or browser tries access expired files.

One of our recent projects needed a very simple CDN module for Drupal 8. Drupal 7 already has a great easy-to-use CDN module, however Drupal 8 version is still under development and doesn't have downloadable development version. Quick internet search returned almost nothing promising except for the blog post describing URL alteration in Drupal 8 and CDN implementation.

The example was using deprecated code and after quick code cleanup I was able to make a version that was functioning in the most recent version of Drupal 8. Now I am sharing the module here (Github).

The module is a very simple. Basically it is implementation of two hooks: HOOK_file_url_alter(&$uri) and HOOK_css_alter(&$css).

Once enabled you can set configuration options via settings.php or by accessing admin/config/services/cdn-pull-origin page:

$config['cdn_pull_origin.settings'] = [
  // CDN could be conditionally disabled here.
  'enabled' => TRUE,
  'domain'  => 'https://d111111abcdef8.cloudfront.net',
];

Download

Update: CDN module now available for Drupal 8 https://www.drupal.org/project/cdn