Skip to content

Commit

Permalink
Filter duplicate extensions by src URL
Browse files Browse the repository at this point in the history
Fixes #1191
  • Loading branch information
sebastianbenz committed Apr 6, 2021
1 parent 082fd32 commit 2efc49d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/optimizer/lib/transformers/ReorderHeadTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class HeadNodes {
}

_removeDuplicateCustomExtensions(extensions) {
const nodesByName = new Map();
const nodesBySrc = new Map();
for (const node of extensions) {
const name = this._getName(node);
nodesByName.set(name, node);
const src = node.attribs['src'];
nodesBySrc.set(src, node);
}
return Array.from(nodesByName.values());
return Array.from(nodesBySrc.values());
}

appendToHead(head) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html >
<head>
<link rel="stylesheet" href="https://cdn.ampproject.org/v0.css">
<script async src="https://cdn.ampproject.org/v0.mjs" type="module" crossorigin="anonymous"></script>
<script async nomodule src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js" custom-element="amp-experiment"></script>
<script async custom-element="amp-experiment" src="https://cdn.ampproject.org/v0/amp-experiment-0.1.mjs" type="module" crossorigin="anonymous"></script>
<script async nomodule src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js" custom-template="amp-mustache"></script>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.mjs" type="module" crossorigin="anonymous"></script>
<link href="https://example.com/favicon.ico" rel="icon">
<link rel="preload" href="https://cdn.ampproject.org/v0.css" as="style">
<link href="https://fonts.googleapis.com/css?foobar" rel="stylesheet" type="text/css">
<link as="script" crossorigin="anonymous" href="https://cdn.ampproject.org/v0.mjs" rel="modulepreload">
</head>
<body></body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html >
<head>
<script async nomodule src="https://cdn.ampproject.org/v0.js"></script>
<script async src="https://cdn.ampproject.org/v0.mjs" type="module" crossorigin="anonymous"></script>
<script async nomodule src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js" custom-template="amp-mustache"></script>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.mjs" type="module" crossorigin="anonymous"></script>
<script async nomodule src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js" custom-element="amp-experiment"></script>
<script async nomodule src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js" custom-element="amp-experiment"></script>
<script async custom-element="amp-experiment" src="https://cdn.ampproject.org/v0/amp-experiment-0.1.mjs" type="module" crossorigin="anonymous"></script>
<script async custom-element="amp-experiment" src="https://cdn.ampproject.org/v0/amp-experiment-0.1.mjs" type="module" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.ampproject.org/v0.css">
<link href="https://fonts.googleapis.com/css?foobar" rel="stylesheet" type="text/css">
<link href="https://example.com/favicon.ico" rel="icon">
<link as="script" crossorigin="anonymous" href="https://cdn.ampproject.org/v0.mjs" rel="modulepreload">
<link rel="preload" href="https://cdn.ampproject.org/v0.css" as="style">
</head>
<body></body>
</html>

0 comments on commit 2efc49d

Please sign in to comment.