diff --git a/Model/Controller/ResultPlugin.php b/Model/Controller/ResultPlugin.php index 648bf2c..f68c667 100644 --- a/Model/Controller/ResultPlugin.php +++ b/Model/Controller/ResultPlugin.php @@ -80,6 +80,19 @@ public function aroundRenderResult( return $result; } + $ignoredStrings = $this->scopeConfig->getValue( + 'mfrocketjavascript/general/ignore_deferred_javascript_with', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE); + $ignoredStrings = explode("\n", str_replace("\r", "\n", $ignoredStrings)); + foreach ($ignoredStrings as $key => $ignoredString) { + $ignoredString = trim($ignoredString); + if (!$ignoredString) { + unset($ignoredStrings[$key]); + } else { + $ignoredStrings[$key] = $ignoredString; + } + } + $html = $response->getBody(); $scripts = []; @@ -107,6 +120,13 @@ public function aroundRenderResult( continue; } + foreach ($ignoredStrings as $ignoredString) { + if (false !== stripos($script, $ignoredString)) { + $start++; + continue 2; + } + } + $html = str_replace($script, '', $html); $scripts[] = $script; } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 6127396..a2d2b26 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -39,6 +39,13 @@ Enter page patches each in a new line. "*" means any path, you can use it at the beginning or end. + + + + 1 + + data-rocketjavascript="false" will automatically be ignored. Example <script data-rocketjavascript="false">/* some script *</script>]]> + Please note that this option only works with enabled JavaScript Bundling (Configuration > Advanced > Developer > JavaScript Settings > Enable JavaScript Bundling). diff --git a/etc/config.xml b/etc/config.xml index c6836dc..56f71fd 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -17,6 +17,7 @@ checkout/* onestepcheckout/* + www.googletagmanager.com 1 jquery.min.js mage/common.min.js