 core/core.libraries.yml                            | 12 ++++++------
 .../Drupal/Core/Asset/JsCollectionOptimizer.php    |  8 +++++++-
 .../Drupal/Core/Asset/LibraryDiscoveryParser.php   |  5 +++++
 .../Core/Asset/LibraryDiscoveryParserTest.php      | 22 ++++++++++++++++++++++
 .../Core/Asset/library_test_files/js.libraries.yml |  4 ++++
 5 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/core/core.libraries.yml b/core/core.libraries.yml
index 71c923f..d0cfb58 100644
--- a/core/core.libraries.yml
+++ b/core/core.libraries.yml
@@ -21,7 +21,7 @@ classList:
     url: https://github.com/eligrey/classList.js/blob/master/LICENSE.md
     gpl-compatible: true
   js:
-    assets/vendor/classList/classList.min.js: { weight: -21, browsers: { IE: 'lte IE 9', '!IE': false } }
+    assets/vendor/classList/classList.min.js: { weight: -21, browsers: { IE: 'lte IE 9', '!IE': false }, minified: true }
 
 ckeditor:
   remote: https://github.com/ckeditor/ckeditor-dev
@@ -31,7 +31,7 @@ ckeditor:
     url: https://github.com/ckeditor/ckeditor-dev/blob/887d81ac1824008b690e439a1b29eb4f13b51212/LICENSE.md
     gpl-compatible: true
   js:
-    assets/vendor/ckeditor/ckeditor.js: { preprocess: false }
+    assets/vendor/ckeditor/ckeditor.js: { preprocess: false, minified: true }
 
 domready:
   remote: https://github.com/ded/domready
@@ -41,7 +41,7 @@ domready:
     url: https://github.com/ded/domready/blob/v1.0.6/LICENSE
     gpl-compatible: true
   js:
-    assets/vendor/domready/ready.min.js: { weight: -21 }
+    assets/vendor/domready/ready.min.js: { weight: -21, minified: true }
 
 drupal:
   version: VERSION
@@ -299,7 +299,7 @@ html5shiv:
     url: http://www.gnu.org/licenses/gpl-2.0.html
     gpl-compatible: true
   js:
-    assets/vendor/html5shiv/html5.js: { every_page: true, weight: -22, browsers: { IE: 'lte IE 8', '!IE': false } }
+    assets/vendor/html5shiv/html5.js: { every_page: true, weight: -22, browsers: { IE: 'lte IE 8', '!IE': false }, minified: true }
 
 jquery:
   remote: https://github.com/jquery/jquery
@@ -332,7 +332,7 @@ jquery.farbtastic:
     url: https://github.com/mattfarina/farbtastic/blob/master/LICENSE.txt
     gpl-compatible: true
   js:
-    assets/vendor/farbtastic/farbtastic.js: {}
+    assets/vendor/farbtastic/farbtastic.js: { minified: true }
   css:
     component:
       assets/vendor/farbtastic/farbtastic.css: {}
@@ -761,7 +761,7 @@ modernizr:
     gpl-compatible: true
   version: v2.6.2
   js:
-    assets/vendor/modernizr/modernizr.min.js: { every_page: true, preprocess: 0, scope: header, weight: -21 }
+    assets/vendor/modernizr/modernizr.min.js: { every_page: true, preprocess: 0, scope: header, weight: -21, minified: true }
 
 normalize:
   remote: https://github.com/necolas/normalize.css
diff --git a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php
index 2356479..68626ec 100644
--- a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php
+++ b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php
@@ -112,7 +112,13 @@ public function optimize(array $js_assets) {
               // Concatenate each asset within the group.
               $data = '';
               foreach ($js_group['items'] as $js_asset) {
-                $data .= $this->optimizer->optimize($js_asset);
+                // Optimize this JS file, but only if it's not yet minified.
+                if (isset($js_asset['minified']) && $js_asset['minified']) {
+                  $data .= file_get_contents($js_asset['data']);
+                }
+                else {
+                  $data .= $this->optimizer->optimize($js_asset);
+                }
                 // Append a ';' and a newline after each JS file to prevent them
                 // from running together.
                 $data .= ";\n";
diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
index 3729161..1aefe11 100644
--- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
+++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
@@ -177,6 +177,11 @@ public function buildByExtension($extension) {
             $options['version'] = $library['version'];
           }
 
+          // Set the 'minified' flag is on JS file assets, default to FALSE.
+          if ($type == 'js' && $options['type'] == 'file') {
+            $options['minified'] = isset($options['minified']) ? $options['minified'] : FALSE;
+          }
+
           $library[$type][] = $options;
         }
       }
diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php
index dde3023..89a878c 100644
--- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php
+++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php
@@ -347,6 +347,28 @@ public function testLibraryWithDataTypes() {
   }
 
   /**
+   * Tests a library with JavaScript-specific flags.
+   *
+   * @covers ::buildByExtension()
+   */
+  public function testLibraryWithJavaScript() {
+    $this->moduleHandler->expects($this->atLeastOnce())
+      ->method('moduleExists')
+      ->with('js')
+      ->will($this->returnValue(TRUE));
+
+    $path = __DIR__ . '/library_test_files';
+    $path = substr($path, strlen(DRUPAL_ROOT) + 1);
+    $this->libraryDiscoveryParser->setPaths('module', 'js', $path);
+
+    $libraries = $this->libraryDiscoveryParser->buildByExtension('js');
+    $library = $libraries['example'];
+
+    $this->assertCount(2, $library['js']);
+    $this->assertEquals(FALSE, $library['js'][0]['minified']);
+    $this->assertEquals(TRUE, $library['js'][1]['minified']);
+  }
+  /**
    * Tests that an exception is thrown when license is missing when 3rd party.
    *
    * @expectedException \Drupal\Core\Asset\Exception\LibraryDefinitionMissingLicenseException
diff --git a/core/tests/Drupal/Tests/Core/Asset/library_test_files/js.libraries.yml b/core/tests/Drupal/Tests/Core/Asset/library_test_files/js.libraries.yml
new file mode 100644
index 0000000..0fa6115
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Asset/library_test_files/js.libraries.yml
@@ -0,0 +1,4 @@
+example:
+  js:
+    js/unminified.js: {}
+    js/minified.js: { minified: true }
