4

I would like to add my own external JS sources at the very end of the body tag in the Craft control panel.

I've already tried using:

{% do view.registerJsFile("<CDN_URL>", {position:3}) %}

according to https://www.yiiframework.com/doc/api/2.0/yii-web-view#registerJsFile()-detail, but Craft is always adding its own JS sources after mine.

Any help would be appreciated!

Brad Bell
  • 67,440
  • 6
  • 73
  • 143

1 Answers1

4

You can set the CP asset as depency then it will be loaded after it

{% do view.registerJsFile("<CDN_URL>",{
    depends: 'craft\\web\\assets\\cp\\CpAsset',
    position:3
}) %}

That's because Yii2 will always register Bundles without any dependencies first / in the order they are defined. If you require the CpAsset it will be loaded afterwards

Robin Schambach
  • 19,713
  • 1
  • 19
  • 44