Skip to content

Commit

Permalink
Use AUTO_EXTENSION_IMPORT config value
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Jun 16, 2021
1 parent f485bcf commit 3d80083
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Optimizer/Transformer/AutoExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down

0 comments on commit 3d80083

Please sign in to comment.