PluginProbe
JCH Optimize / trunk
JCH Optimize vtrunk
6.0.2 6.0.1 trunk 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.10.0 2.2.0 2.2.1 All 58 releases
jch-optimize / lib / src / ConfigureHelper.php

ConfigureHelper.php in JCH Optimize trunk, at lib/src/ConfigureHelper.php

59 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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