yii2-minify-view icon indicating copy to clipboard operation
yii2-minify-view copied to clipboard

Google Recaptcha does not load using yii2-minify-view

Open thyseus opened this issue 7 years ago • 6 comments

Hi rmrevin,

at first: thanks a lot for your wonderful extension. It is great !

unfortunately i stumbled upon a problem:

I use the https://github.com/himiklab/yii2-recaptcha-widget to display an captcha on my page.

This widget loads a .js file directly from google: https://github.com/himiklab/yii2-recaptcha-widget/blob/master/ReCaptcha.php#L109

When activating your extension, the .js file stops being loaded ! I have no Idea why this happens. This is my configuration - which is very standard:

[
            'class' => '\rmrevin\yii\minify\View',
            'enableMinify' => true,
            'concatCss' => true,
            'minifyCss' => true,
            'concatJs' => true,
            'minifyJs' => true,
            'minifyOutput' => true,
            'webPath' => '@web',
            'basePath' => '@webroot',
            'minifyPath' => '@webroot/minify',
            'jsPosition' => [\yii\web\View::POS_END],
            'forceCharset' => 'UTF-8',
            'expandImports' => true,
            'compressOptions' => ['extra' => true],
        ],

There is no AssetBundle to ignore since the file gets loaded from google. I also tried to do this:

  'excludeFiles' => [
                '//www.google.com/recaptcha/api.js?hl=de&render=explicit&onload=recaptchaOnloadCallback',
          
            ],

but without success.

Do you have any ideas ?

Thanks a lot in advance !

thyseus avatar Feb 14 '18 12:02 thyseus

hi @thyseus , the problem is not in min js, is in jsPosition, if you change POS_END to POS_HEAD It will work.

metola avatar Feb 23 '18 10:02 metola

@metola This does work indeed. Thanks a lot !

Is it possible to only use POS_HEAD on a specific controller & action (where the captcha is), but POS_END everywhere else? Javascript "feels" te be more performant to the end user if it is loaded as late as possible.

thyseus avatar Feb 26 '18 12:02 thyseus

Same problem, jsPosition not solve it.

ReCaptcha.php added file by this code

const JS_API_URL = '//www.google.com/recaptcha/api.js';
$view->registerJsFile(
    self::JS_API_URL . '?' . $arguments,
    ['position' => $view::POS_END, 'async' => true, 'defer' => true],
    'recaptcha-api'
);

but some reason extension not ignoring it

wa1kb0y avatar Mar 17 '18 20:03 wa1kb0y

Come across the same issue here. Not a fan of the fix t change the POS as _end is best practice for JS but doing so does fix the issue.

adamjamesevans avatar Jun 04 '18 17:06 adamjamesevans

@thyseus @wa1kb0y put this in your config:

 'excludeFiles' => [
     'recaptcha-api'
]

n30fly avatar Jun 15 '18 10:06 n30fly

@n30fly it works, ty

wa1kb0y avatar Aug 19 '18 12:08 wa1kb0y