1

Perhaps in some way related to this, I've got a couple of front-end pages on our website that pull in the following files, which seem to all be CP files. These two pages each utilize plugins I've written, each one a different plugin, so there must be something I'm doing in my plugins that calls this stuff in. Any hints?

selectize.css
craft.css
charts.css 
axios.min.js
d3.js
element-resize-detector.js
jquery.js
jquery.mobile-events.min.js
velocity.js
garnish.js
jquery-ui.min.js
jquery.payment.js
picturefill.js
selectize.js
jquery.fileupload.js
xregexp-all.js
fabric.js
Craft.min.js

EDIT: Here is the relevant asset-bundle:

class LivestreamAsset extends AssetBundle
{
    // Public Methods
    // =========================================================================

    /**
     * Initializes the bundle.
     */
    public function init()
    {
        // define the path that your publishable resources live
        $this->sourcePath = "@kr37/livestream/assetbundles/livestream/dist";

        // define the dependencies
        $this->depends = [
            CpAsset::class,
        ];

        // define the relative path to CSS/JS files that should be registered with the page
        // when this asset bundle is registered
        $this->js = [
            'js/Livestream.js',
        ];

        $this->css = [
            'css/Livestream.css',
        ];

        parent::init();
    }
}
  • 2
    are your plugin assets depending on CpAsset? those files are included in page by CpAsset. - look for YourPluginAsset file in src/assets folder of your plugin and check $this->depend=[CpAsset::class]; also you are probably registering YourPluginAsset class in your front end template. – user9975 May 15 at 13:58
  • 1
    You nailed it. I was re-purposing an assetbundle created by pluginfactory.io, and didn't notice that in there. Removing that fixes the problem. If you write it up as an answer, I'll accept it. (Also I edited my question to include the offending lines.) – kr37 May 15 at 20:50
2

those CP files are included by CpAsset asset bundle.

if your plugin asset bundle depends on CpAsset:

class YourPluginAsset extends AssetBundle
{
    public function init()
    {
        $this->sourcePath = __DIR__ . '/dist';
        $this->depends = [
         CpAsset::class,
        ]
     //....
    }
}

and if you register your plugin asset in frontend or backend template:

{% do view.registerAssetBundle("ns\\prefix\\YourPluginAsset") %}

or via controller:

 $this->view->registerAssetBundle(YourPluginAsset::class);

those file are added to that page automatically.

| improve this answer | |
  • Thank you. Very helpful! – kr37 May 16 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.