diff --git a/core/lib/Drupal/Core/Asset/AssetOptimizerInterface.php b/core/lib/Drupal/Core/Asset/AssetOptimizerInterface.php
index 31c4b9371b3b0696f2035730a211dd5495925c1b..171583dc9f73e197ef72f084d1319de27ebfb237 100644
--- a/core/lib/Drupal/Core/Asset/AssetOptimizerInterface.php
+++ b/core/lib/Drupal/Core/Asset/AssetOptimizerInterface.php
@@ -22,4 +22,15 @@ interface AssetOptimizerInterface {
    */
   public function optimize(array $asset);
 
+  /**
+   * Removes unwanted content from an asset.
+   *
+   * @param string $content
+   *   The content of an asset.
+   *
+   * @return string
+   *   The cleaned asset's contents.
+   */
+  public function clean($content);
+
 }
diff --git a/core/lib/Drupal/Core/Asset/CssOptimizer.php b/core/lib/Drupal/Core/Asset/CssOptimizer.php
index b93a638f9e41794f1b25c2177522ce4460b12dc4..673012b87f467aba54b1e9a6718bfa5ff3fb1b8c 100644
--- a/core/lib/Drupal/Core/Asset/CssOptimizer.php
+++ b/core/lib/Drupal/Core/Asset/CssOptimizer.php
@@ -39,12 +39,31 @@ public function optimize(array $css_asset) {
     }
   }
 
+  /**
+   * Processes the contents of a CSS asset for cleanup.
+   *
+   * @param string $contents
+   *   The contents of the CSS asset.
+   *
+   * @return string
+   *   Contents of the CSS asset.
+   */
+  public function clean($contents) {
+    // Remove multiple charset declarations for standards compliance (and fixing
+    // Safari problems).
+    $contents = preg_replace('/^@charset\s+[\'"](\S*?)\b[\'"];/i', '', $contents);
+
+    return $contents;
+  }
+
   /**
    * Build aggregate CSS file.
    */
   protected function processFile($css_asset) {
     $contents = $this->loadFile($css_asset['data'], TRUE);
 
+    $contents = $this->clean($contents);
+
     // Get the parent directory of this file, relative to the Drupal root.
     $css_base_path = substr($css_asset['data'], 0, strrpos($css_asset['data'], '/'));
     // Store base path.
@@ -161,8 +180,8 @@ protected function loadNestedFile($matches) {
    *   Contents of the stylesheet including the imported stylesheets.
    */
   protected function processCss($contents, $optimize = FALSE) {
-    // Remove multiple charset declarations for standards compliance (and fixing Safari problems).
-    $contents = preg_replace('/^@charset\s+[\'"](\S*?)\b[\'"];/i', '', $contents);
+    // Remove unwanted CSS code that cause issues.
+    $contents = $this->clean($contents);
 
     if ($optimize) {
       // Perform some safe CSS optimizations.
diff --git a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php
index 68626ec4208a55dd4809f07c14d8c72aa784d484..a21725dedb9961a011f0706b92fbafc15b5e73ec 100644
--- a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php
+++ b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php
@@ -123,6 +123,8 @@ public function optimize(array $js_assets) {
                 // from running together.
                 $data .= ";\n";
               }
+              // Remove unwanted JS code that cause issues.
+              $data = $this->optimizer->clean($data);
               // Dump the optimized JS for this group into an aggregate file.
               $uri = $this->dumper->dump($data, 'js');
               // Set the URI for this group's aggregate file.
diff --git a/core/lib/Drupal/Core/Asset/JsOptimizer.php b/core/lib/Drupal/Core/Asset/JsOptimizer.php
index e6ad2939e4811444e7b57bd16e5f88c56791b2fe..bd004a512a3d103f53cd055658757bb0a2394712 100644
--- a/core/lib/Drupal/Core/Asset/JsOptimizer.php
+++ b/core/lib/Drupal/Core/Asset/JsOptimizer.php
@@ -28,4 +28,20 @@ public function optimize(array $js_asset) {
     return file_get_contents($js_asset['data']);
   }
 
+  /**
+   * Processes the contents of a javascript asset for cleanup.
+   *
+   * @param string $contents
+   *   The contents of the javascript asset.
+   *
+   * @return string
+   *   Contents of the javascript asset.
+   */
+  public function clean($contents) {
+    // Remove JS source and source mapping urls or these may cause 404 errors.
+    $contents = preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=\s*(\S*?)\s*$/m', '', $contents);
+
+    return $contents;
+  }
+
 }
diff --git a/core/tests/Drupal/Tests/Core/Asset/JsOptimizerUnitTest.php b/core/tests/Drupal/Tests/Core/Asset/JsOptimizerUnitTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..13bd77cbbc68e9b0b7b9eb3570968e02329fc6d4
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Asset/JsOptimizerUnitTest.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Asset\JsOptimizerUnitTest.
+ */
+
+namespace Drupal\Tests\Core\Asset;
+
+use Drupal\Core\Asset\JsOptimizer;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * Tests the JS asset optimizer.
+ *
+ * @group Asset
+ */
+class JsOptimizerUnitTest extends UnitTestCase {
+
+  /**
+   * A JS asset optimizer.
+   *
+   * @var \Drupal\Core\Asset\JsOptimizer object.
+   */
+  protected $optimizer;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->optimizer = new JsOptimizer();
+  }
+
+  /**
+   * Provides data for the JS asset cleaning test.
+   *
+   * @see \Drupal\Core\Asset\JsOptimizer::clean().
+   *
+   * @returns array
+   *   An array of test data.
+   */
+  function providerTestClean() {
+    $path = dirname(__FILE__)  . '/js_test_files/';
+    return array(
+      // File. Tests:
+      // - Stripped sourceMappingURL with comment # syntax.
+      0 => array(
+        file_get_contents($path . 'source_mapping_url.min.js'),
+        file_get_contents($path . 'source_mapping_url.min.js.optimized.js'),
+      ),
+      // File. Tests:
+      // - Stripped sourceMappingURL with comment @ syntax.
+      1 => array(
+        file_get_contents($path . 'source_mapping_url_old.min.js'),
+        file_get_contents($path . 'source_mapping_url_old.min.js.optimized.js'),
+      ),
+      // File. Tests:
+      // - Stripped sourceURL with comment # syntax.
+      2 => array(
+        file_get_contents($path . 'source_url.min.js'),
+        file_get_contents($path . 'source_url.min.js.optimized.js'),
+      ),
+      // File. Tests:
+      // - Stripped sourceURL with comment @ syntax.
+      3 => array(
+        file_get_contents($path . 'source_url_old.min.js'),
+        file_get_contents($path . 'source_url_old.min.js.optimized.js'),
+      ),
+    );
+  }
+
+  /**
+   * Tests cleaning of a JS asset group containing 'type' => 'file'.
+   *
+   * @dataProvider providerTestClean
+   */
+  function testClean($js_asset, $expected) {
+    $this->assertEquals($expected, $this->optimizer->clean($js_asset));
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/Core/Asset/css_test_files/charset_newline.css b/core/tests/Drupal/Tests/Core/Asset/css_test_files/charset_newline.css
index 68f3f42b2cfa1baf32e08c5d4c60ec1ef24e29f9..21aacf2dcd672d706bfeb6589e9c7280743b3fdc 100644
--- a/core/tests/Drupal/Tests/Core/Asset/css_test_files/charset_newline.css
+++ b/core/tests/Drupal/Tests/Core/Asset/css_test_files/charset_newline.css
@@ -1,2 +1,2 @@
-@charset 'UTF-8';
+@charset "UTF-8";
 html{font-family:"sans-serif";}
diff --git a/core/tests/Drupal/Tests/Core/Asset/css_test_files/charset_sameline.css.optimized.css b/core/tests/Drupal/Tests/Core/Asset/css_test_files/charset_sameline.css.optimized.css
deleted file mode 100644
index c9e6aded3cd9f46d3a97b3e2f791f40d1dfcf66c..0000000000000000000000000000000000000000
--- a/core/tests/Drupal/Tests/Core/Asset/css_test_files/charset_sameline.css.optimized.css
+++ /dev/null
@@ -1 +0,0 @@
-html{font-family:"sans-serif";}
diff --git a/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url.min.js b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url.min.js
new file mode 100644
index 0000000000000000000000000000000000000000..4e133bdbe29e05a41ad411ad4c118073d2a50a8a
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url.min.js
@@ -0,0 +1,2 @@
+(function($) { "use strict"; })
+//# sourceMappingURL=source_mapping_url.min.map
diff --git a/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url.min.js.optimized.js b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url.min.js.optimized.js
new file mode 100644
index 0000000000000000000000000000000000000000..ec09066aa14a9a84bcf0e4bb803ea2349404dc05
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url.min.js.optimized.js
@@ -0,0 +1 @@
+(function($) { "use strict"; })
diff --git a/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url_old.min.js b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url_old.min.js
new file mode 100644
index 0000000000000000000000000000000000000000..b937b8691a90e7587f5b3d5fe19203c580c63924
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url_old.min.js
@@ -0,0 +1,2 @@
+(function($) { "use strict"; })
+//@ sourceMappingURL=source_mapping_url.min.map
diff --git a/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url_old.min.js.optimized.js b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url_old.min.js.optimized.js
new file mode 100644
index 0000000000000000000000000000000000000000..ec09066aa14a9a84bcf0e4bb803ea2349404dc05
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_mapping_url_old.min.js.optimized.js
@@ -0,0 +1 @@
+(function($) { "use strict"; })
diff --git a/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url.min.js b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url.min.js
new file mode 100644
index 0000000000000000000000000000000000000000..efb20328652671205020660379944feb6dacc03e
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url.min.js
@@ -0,0 +1,2 @@
+(function($) { "use strict"; })
+//# sourceURL=source_mapping_url.js
diff --git a/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url.min.js.optimized.js b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url.min.js.optimized.js
new file mode 100644
index 0000000000000000000000000000000000000000..ec09066aa14a9a84bcf0e4bb803ea2349404dc05
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url.min.js.optimized.js
@@ -0,0 +1 @@
+(function($) { "use strict"; })
diff --git a/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url_old.min.js b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url_old.min.js
new file mode 100644
index 0000000000000000000000000000000000000000..dd26bd587390325182894a19d39c53f69eda7f5c
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url_old.min.js
@@ -0,0 +1,2 @@
+(function($) { "use strict"; })
+//@ sourceURL=source_mapping_url.js
diff --git a/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url_old.min.js.optimized.js b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url_old.min.js.optimized.js
new file mode 100644
index 0000000000000000000000000000000000000000..ec09066aa14a9a84bcf0e4bb803ea2349404dc05
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Asset/js_test_files/source_url_old.min.js.optimized.js
@@ -0,0 +1 @@
+(function($) { "use strict"; })