ampproject / amp-toolbox

A collection of AMP tools making it easier to publish and host AMP pages.
Apache License 2.0
449 stars 243 forks source link

ReorderHead deduplicates based on name only #1191

Closed schlessera closed 3 years ago

schlessera commented 3 years ago

The ReorderHead transformer uses the extension name to deduplicate scripts for a same extension. This means that if multiple <script> elements use the same extension name (like for .mjs script + nomodule fallback), they are "deduplicated" and one of these gets lost.

The ReorderHead transformer needs a more robust algorithm for deduplication that takes the requirement for two <script> elements for ESM into account. Here's what the Go version is doing: https://github.com/ampproject/amppackager/commit/8e2622daa536d5d49dbb6c80f39cbffe65053f72#diff-4e49b75e7da4b38f1a1be19bfc9c6b9e12dbe964eda574cf83ee419776c782f0R80-R94

sebastianbenz commented 3 years ago

Oh yes! We were just lucky to run RewriteAmpUrls after ReorderHeadTransformer...