Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Recaptcha does not load using yii2-minify-view #63

Open
thyseus opened this issue Feb 14, 2018 · 6 comments
Open

Google Recaptcha does not load using yii2-minify-view #63

thyseus opened this issue Feb 14, 2018 · 6 comments

Comments

@thyseus
Copy link

thyseus commented Feb 14, 2018

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 !

@metola
Copy link

metola commented Feb 23, 2018

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

@thyseus
Copy link
Author

thyseus commented Feb 26, 2018

@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.

@wa1kb0y
Copy link

wa1kb0y commented Mar 17, 2018

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

@adamjamesevans
Copy link

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.

@n30fly
Copy link

n30fly commented Jun 15, 2018

@thyseus @wa1kb0y put this in your config:

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

@wa1kb0y
Copy link

wa1kb0y commented Aug 19, 2018

@n30fly it works, ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants