If I have to use JqueryAsset implemented by myself for a specified version , the yii\web\View::registerJs() method will register the built-in yii\web\JqueryAsset automatically ! Then I have two jquery.js in one Page ~~~~
ps:
Just remove it !
Do not use JqueryAsset in yii\web\View::registerJs() to deal with the yii\web\View::POS_READY things.
Alternatively , just use NATIVE javascript instead.
NATIVE javascript
Also consider to remove [yii\web\Jquery] from yii2 ?
| Q | A |
| --- | --- |
| Yii version | 2.0.9 |
| PHP version | PHP 7.0 |
| Operating system | OS X |
Use Dependecy Injection Container and override yii\web\JqueryAsset with your own.
Yii::$container->set('yii\web\JqueryAsset', 'you\own\JqueryAsset');
See Dependeny injection container guide page to know more.
_This is an automated comment, triggered by adding the label question._
Please note, that the GitHub Issue Tracker is for bug reports and feature requests only.
We are happy to help you on the support forum, on IRC (#yii on freenode), or Gitter.
Please use one of the above mentioned resources to discuss the problem.
If the result of the discussion turns out that there really is a bug in the framework, feel free to
come back and provide information on how to reproduce the issue. This issue will be closed for now.
Or even easier - override bundles array
http://www.yiiframework.com/doc-2.0/yii-web-assetmanager.html
I know the two ways you said above, but what I want to say is not that.
For example , If I use View::registerJs() , but I don't want to use Jquery in my page. Maybe I can't use it because of my BOSS , my Leader etc.
This is what I want to express.
Why hard-coding the Jquery in the View class?
@SilverFire
JqueryAsset is loaded only in case you are using View::POS_READY or View::POS_LOAD position for your JavaScript files. It is loaded because these positions require JQuery functions to be actually applied.
If you do not want JQuery o be involved in the process you should use other script positions.
Thank you
In general jQuery $(document).ready() statement can be replaced by pure JavaScript analog:
document.addEventListener("DOMContentLoaded", function(event) {
//do work
});
Resolved via #14865
Most helpful comment
In general jQuery
$(document).ready()statement can be replaced by pure JavaScript analog: