In yii2
I have put all my js code in 1 file using yii2-assets-auto-compress
plugin, including jQuery lib. Loading this file is async
to speed up page load. But, if there are forms on the page, yii adds yiiActiveForm()
at the end of </body>
. So, the error is jQuery is not defined
.
How to manage this problem? Firstly, I can make call yiiActiveForm()
manually from script.js, but how to turn it off automatically load at the end of the body? Generally, that's not convenient, because there might be other scripts that append js code. Maybe someone knows how append js code with this yii2-assets-auto-compress
plugin?
<script src="/assets/js-compress/script.js?" async="async"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('#w0').yiiActiveForm([],[]);
});
</script>
</body>