 cdn.module                |  7 ++++++
 cdn.services.yml          |  6 +++++
 src/Asset/AssetDumper.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)

diff --git a/cdn.module b/cdn.module
index 0e337e2..a25623d 100644
--- a/cdn.module
+++ b/cdn.module
@@ -14,3 +14,10 @@ function cdn_file_url_alter(&$uri) {
     $uri = $result;
   }
 }
+
+/**
+ * Implements hook_advagg_current_hooks_hash_array_alter().
+ */
+function cdn_advagg_current_hooks_hash_array_alter() {
+  $aggregate_settings['variables']['cdn'] = \Drupal::service('cdn.settings')->getHash();
+}
diff --git a/cdn.services.yml b/cdn.services.yml
index 2560a0f..3a95518 100644
--- a/cdn.services.yml
+++ b/cdn.services.yml
@@ -29,3 +29,9 @@ services:
     class: Drupal\cdn\PathProcessor\CdnFarfuturePathProcessor
     tags:
       - { name: path_processor_inbound }
+
+  cdn.asset.css.dumper:
+    public: false
+    class: Drupal\cdn\Asset\AssetDumper
+    decorates: asset.css.dumper
+    arguments: ['@cdn.asset.css.dumper.inner', '@cdn.settings']
diff --git a/src/Asset/AssetDumper.php b/src/Asset/AssetDumper.php
new file mode 100644
index 0000000..7bccde7
--- /dev/null
+++ b/src/Asset/AssetDumper.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Drupal\cdn\Asset;
+
+use Drupal\cdn\CdnSettings;
+use Drupal\Component\Utility\Crypt;
+use Drupal\Core\Asset\AssetDumperInterface;
+
+/**
+ * Dumps a CSS or JavaScript asset.
+ */
+class AssetDumper implements AssetDumperInterface {
+
+
+  public function __construct(AssetDumperInterface $dumper, CdnSettings $settings) {
+    $this->decoratedDumper = $dumper;
+    $this->settings = $settings;
+  }
+
+  /**
+   * {@inheritdoc}
+   *
+   * The file name for the CSS or JS cache file is generated from the hash of
+   * the aggregated contents of the files in $data. This forces proxies and
+   * browsers to download new CSS when the CSS changes.
+   */
+  public function dump($data, $file_extension) {
+    if ($file_extension !== 'css') {
+      return $this->decoratedDumper->dump($data, $file_extension);
+    }
+    else {
+      // Prefix filename to prevent blocking by firewalls which reject files
+      // starting with "ad*".
+      $filename = $file_extension . '_' . Crypt::hashBase64($data) . '.' . $file_extension;
+
+      // THIS IS THE ONLY MODIFICATION TO THE LOGIC THAT WE MAKE!!!!!!!!!!!!!!!!
+      $filename = $this->settings->getHash() . '_' . $filename;
+
+      // Create the css/ or js/ path within the files folder.
+      $path = 'public://' . $file_extension;
+      $uri = $path . '/' . $filename;
+      // Create the CSS or JS file.
+      file_prepare_directory($path, FILE_CREATE_DIRECTORY);
+      if (!file_exists($uri) && !file_unmanaged_save_data($data, $uri, FILE_EXISTS_REPLACE)) {
+        return FALSE;
+      }
+      // If CSS/JS gzip compression is enabled and the zlib extension is available
+      // then create a gzipped version of this file. This file is served
+      // conditionally to browsers that accept gzip using .htaccess rules.
+      // It's possible that the rewrite rules in .htaccess aren't working on this
+      // server, but there's no harm (other than the time spent generating the
+      // file) in generating the file anyway. Sites on servers where rewrite rules
+      // aren't working can set css.gzip to FALSE in order to skip
+      // generating a file that won't be used.
+      if (extension_loaded('zlib') && \Drupal::config('system.performance')->get($file_extension . '.gzip')) {
+        if (!file_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
+          return FALSE;
+        }
+      }
+      return $uri;
+    }}
+
+}
