Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Unified Diff: lib/src/codegen/html_codegen.dart

Issue 1145893008: fixes #182, avoid injecting a duplicate link rel=stylesheet (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/src/dependency_graph.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/html_codegen.dart
diff --git a/lib/src/codegen/html_codegen.dart b/lib/src/codegen/html_codegen.dart
index 4f1c7349d0813cdef89d45af2d4892a1fffc38d8..30ba940f247af7dd95a8e3889824eeb4535760e3 100644
--- a/lib/src/codegen/html_codegen.dart
+++ b/lib/src/codegen/html_codegen.dart
@@ -43,13 +43,28 @@ String generateEntryHtml(HtmlSourceNode root, CompilerOptions options) {
if (options.outputDart) return '${document.outerHtml}\n';
var libraries = [];
- var resources = [];
+ var resources = new Set();
visitInPostOrder(root, (n) {
if (n is DartSourceNode) libraries.add(n);
if (n is ResourceSourceNode) resources.add(n);
}, includeParts: false);
- String mainLibraryName;
+ root.htmlResourceNodes.forEach((element, resource) {
+ // Make sure we don't try and add this node again.
+ resources.remove(resource);
+
+ var resourcePath = resourceOutputPath(resource.uri, root.uri);
+ if (resource.cachingHash != null) {
+ resourcePath = _addHash(resourcePath, resource.cachingHash);
+ }
+ var attrs = element.attributes;
+ if (attrs.containsKey('href')) {
+ attrs['href'] = resourcePath;
+ } else if (attrs.containsKey('src')) {
+ attrs['src'] = resourcePath;
+ }
+ });
+
var fragment = new DocumentFragment();
for (var resource in resources) {
var resourcePath = resourceOutputPath(resource.uri, root.uri);
@@ -57,12 +72,15 @@ String generateEntryHtml(HtmlSourceNode root, CompilerOptions options) {
if (resource.cachingHash != null) {
resourcePath = _addHash(resourcePath, resource.cachingHash);
}
- if (ext == '.css') {
- fragment.nodes.add(_cssInclude(resourcePath));
- } else if (ext == '.js') {
+ if (ext == '.js') {
fragment.nodes.add(_libraryInclude(resourcePath));
+ } else if (ext == '.css') {
+ var stylesheetLink = '<link rel="stylesheet" href="$resourcePath">\n';
+ fragment.nodes.add(parseFragment(stylesheetLink));
}
}
+
+ String mainLibraryName;
for (var lib in libraries) {
var info = lib.info;
if (info == null) continue;
@@ -82,10 +100,6 @@ String generateEntryHtml(HtmlSourceNode root, CompilerOptions options) {
Node _libraryInclude(String jsUrl) =>
parseFragment('<script src="$jsUrl"></script>\n');
-/// A tag that loads the .css code.
-Node _cssInclude(String cssUrl) =>
- parseFragment('<link rel="stylesheet" href="$cssUrl">\n');
-
/// A script tag that invokes the main function on the entry point library.
Node _invokeMain(String mainLibraryName) {
var code = mainLibraryName == null
« no previous file with comments | « no previous file | lib/src/dependency_graph.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698