append html imports before the dart script tag
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f1be1f8..4f998f4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+#### 0.10.5+2
+  * Append html imports in front of the dart script tag, if one exists in
+    `document.head`.
+
 #### 0.10.5+1
   * Fix @HtmlImport with relative paths from within folders in deployment mode.
 
diff --git a/lib/build/web_components.dart b/lib/build/web_components.dart
index d1028b2..a5bf002 100644
--- a/lib/build/web_components.dart
+++ b/lib/build/web_components.dart
@@ -32,10 +32,14 @@
       resolver, transform, scriptId, newScriptId,
       errorIfNotFound: false, plugins: plugins);
 
-  // Add all seen imports to the document.
+  // Add all seen imports to the document, before the first dart script tag if
+  // it exists.
+  var dartScript =
+      document.head.querySelector('script[type="application/dart"]');
   for (var importPath in htmlImportRecorder.importPaths) {
-    document.head.append(new dom.Element.tag('link')
-      ..attributes = {'rel': 'import', 'href': importPath,});
+    var import = new dom.Element.tag('link')
+      ..attributes = {'rel': 'import', 'href': importPath,};
+    document.head.insertBefore(import, dartScript);
   }
 
   return initializeBootstrap;
diff --git a/pubspec.yaml b/pubspec.yaml
index ebc2995..d26edac 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: web_components
-version: 0.10.5+1
+version: 0.10.5+2
 author: Polymer.dart Authors <web-ui-dev@dartlang.org>
 homepage: https://www.dartlang.org/polymer-dart/
 description: >
diff --git a/test/build/transformer_test.dart b/test/build/transformer_test.dart
index bafdbcb..e02a731 100644
--- a/test/build/transformer_test.dart
+++ b/test/build/transformer_test.dart
@@ -118,4 +118,53 @@
         bar() {}
         ''',
   }, [], StringFormatter.noNewlinesOrSurroundingWhitespace);
+
+  testPhases('imports go above the dart script', phases, {
+    'b|web/index.html': '''
+        <!DOCTYPE html>
+        <html>
+          <head>
+            <script type="application/dart" src="index.dart"></script>
+          </head>
+          <body>
+          </body>
+        </html>
+        ''',
+    'b|web/index.dart': '''
+        @HtmlImport('package:b/b.html')
+        library b;
+
+        import 'package:web_components/html_import_annotation.dart';
+        import 'package:c/c.dart';
+        ''',
+    'b|lib/b.html': '''
+        <div>b</div>
+        ''',
+    'c|lib/c.dart': '''
+        @HtmlImport('c.html')
+        library c;
+
+        import 'package:web_components/html_import_annotation.dart';
+        ''',
+    'c|lib/c.html': '''
+        <div>c</div>
+        ''',
+    'initialize|lib/initialize.dart': mockInitialize,
+    'web_components|lib/html_import_annotation.dart': mockHtmlImportAnnotation,
+  }, {
+    'b|web/index.html': '''
+        <!DOCTYPE html>
+        <html>
+          <head></head>
+          <body>
+            <div hidden="">
+              <div>c</div>
+              <div>b</div>
+              <script type="application/dart" src="index.bootstrap.initialize.dart">
+              </script>
+            </div>
+          </body>
+        </html>
+        ''',
+  }, [], StringFormatter.noNewlinesOrSurroundingWhitespace);
 }