diff --git a/src/Optimizer/Transformer/AutoExtensions.php b/src/Optimizer/Transformer/AutoExtensions.php index 447ca550c..4b55f20dc 100644 --- a/src/Optimizer/Transformer/AutoExtensions.php +++ b/src/Optimizer/Transformer/AutoExtensions.php @@ -8,6 +8,7 @@ use AmpProject\Dom\Element; use AmpProject\Dom\NodeWalker; use AmpProject\Extension; +use AmpProject\Optimizer\Configuration\AutoExtensionsConfiguration; use AmpProject\Optimizer\Error\CannotParseJsonData; use AmpProject\Optimizer\ErrorCollection; use AmpProject\Optimizer\Transformer; @@ -56,7 +57,11 @@ public function __construct(TransformerConfiguration $configuration, Spec $spec) public function transform(Document $document, ErrorCollection $errors) { $extensionScripts = $this->extractExtensionScripts($document, $errors); - $extensionScripts = $this->addMissingExtensions($document, $extensionScripts); + + if ($this->configuration->get(AutoExtensionsConfiguration::AUTO_EXTENSION_IMPORT)) { + $extensionScripts = $this->addMissingExtensions($document, $extensionScripts); + } + $extensionScripts = $this->removeUnneededExtensions($document, $extensionScripts); $this->renderExtensionScripts($document, $extensionScripts); @@ -77,6 +82,7 @@ private function extractExtensionScripts(Document $document, ErrorCollection $er $nodesToRemove = []; foreach ($document->head->getElementsByTagName(Tag::SCRIPT) as $script) { + /** @var Element $script */ if ($script->getAttribute(Attribute::ID) === Extension::ACCESS) { // Explicitly detect amp-access via the script tag in the header to be able to handle amp-access // extensions.