Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 64daf4d

Browse files
committed
optimization
1 parent c900ad0 commit 64daf4d

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

Diff for: ReCaptcha.php

+17-18
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,7 @@ class ReCaptcha extends InputWidget
8282
/** @var array Additional html widget options, such as `class`. */
8383
public $widgetOptions = [];
8484

85-
public function init()
86-
{
87-
parent::init();
88-
89-
$view = $this->view;
90-
$view->registerJs($this->render('onload'), $view::POS_BEGIN);
91-
}
85+
protected static $firstWidget = true;
9286

9387
public function run()
9488
{
@@ -102,17 +96,22 @@ public function run()
10296
}
10397
}
10498

105-
$arguments = http_build_query([
106-
'hl' => $this->getLanguageSuffix(),
107-
'render' => 'explicit',
108-
'onload' => 'recaptchaOnloadCallback',
109-
]);
110-
111-
$view = $this->view;
112-
$view->registerJsFile(
113-
self::JS_API_URL . '?' . $arguments,
114-
['position' => $view::POS_END, 'async' => true, 'defer' => true]
115-
);
99+
if (self::$firstWidget) {
100+
$view = $this->view;
101+
$arguments = http_build_query([
102+
'hl' => $this->getLanguageSuffix(),
103+
'render' => 'explicit',
104+
'onload' => 'recaptchaOnloadCallback',
105+
]);
106+
$view->registerJsFile(
107+
self::JS_API_URL . '?' . $arguments,
108+
['position' => $view::POS_END, 'async' => true, 'defer' => true]
109+
);
110+
111+
$view->registerJs($this->render('onload'), $view::POS_BEGIN);
112+
113+
self::$firstWidget = false;
114+
}
116115

117116
$this->customFieldPrepare();
118117
echo Html::tag('div', '', $this->buildDivOptions());

0 commit comments

Comments
 (0)