| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* JCH Optimize - Performs several front-end optimizations for fast downloads |
| 5 |
* |
| 6 |
* @package jchoptimize/core |
| 7 |
* @author Samuel Marshall <samuel@jch-optimize.net> |
| 8 |
* @copyright Copyright (c) 2024 Samuel Marshall / JCH Optimize |
| 9 |
* @license GNU/GPLv3, or later. See LICENSE file |
| 10 |
* |
| 11 |
* If LICENSE file missing, see <http://www.gnu.org/licenses/>. |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace JchOptimize\Core; |
| 15 |
|
| 16 |
use JchOptimize\Core\Html\HtmlElementBuilder; |
| 17 |
use JchOptimize\Core\Html\HtmlManager; |
| 18 |
use JchOptimize\Core\Platform\PathsInterface; |
| 19 |
use JchOptimize\Core\Uri\Utils; |
| 20 |
|
| 21 |
use const JCH_DEBUG; |
| 22 |
use const JCH_VERSION; |
| 23 |
|
| 24 |
class ConfigureHelper |
| 25 |
{ |
| 26 |
public function __construct( |
| 27 |
private Registry $params, |
| 28 |
private HtmlManager $htmlManager, |
| 29 |
private PathsInterface $pathsUtils |
| 30 |
) { |
| 31 |
} |
| 32 |
|
| 33 |
public function loadNumElementsScript(): void |
| 34 |
{ |
| 35 |
if (JCH_DEBUG && $this->params->get('elements_above_fold_marker', '0')) { |
| 36 |
$script = HtmlElementBuilder::script(); |
| 37 |
$script->src( |
| 38 |
Utils::uriFor( |
| 39 |
$this->pathsUtils->mediaUrl() . '/configure-helpers/num_elements.js?' . JCH_VERSION, |
| 40 |
) |
| 41 |
)->defer(); |
| 42 |
$this->htmlManager->appendChildToHTML((string)$script, 'body'); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
public function loadDynamicCssElementsScript(): void |
| 47 |
{ |
| 48 |
if (JCH_DEBUG && $this->params->get('critical_css_configure_helper', '0')) { |
| 49 |
$script = HtmlElementBuilder::script(); |
| 50 |
$script->src( |
| 51 |
Utils::uriFor( |
| 52 |
$this->pathsUtils->mediaUrl() . '/configure-helpers/dynamic_css_elements.js?' . JCH_VERSION |
| 53 |
) |
| 54 |
); |
| 55 |
$this->htmlManager->appendChildToHTML((string)$script, 'body'); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|