How do I add js and css files to frontend page loads via a plugin? I did reference this issue: Can a plugin add JS or CSS to the control panel?
but that is for Craft 2.
Reading the docs here: https://docs.craftcms.com/v3/changes-in-craft-3.html#template-tags and here https://docs.craftcms.com/v3/extend/asset-bundles.html
show that Craft 3 is much different. I've looked through several Craft 3 plugins that do load scripts and styles on the frontend but each seems to handle this in very different ways. Is there a straight-forward standard that should be used if a plugin is loaded and needs to add resources to frontend page loads?
On the Asset Bundles doc page, it seems you can link directly to the asset in the plugin init but a comment further down the page suggests that you need to load the assets into the template:
"With that in place, all that is left is to register the asset bundle wherever its JS/CSS files are needed."
or I may be understanding this incorrectly. Can I accomplish what I'm trying just by placing:
$this->sourcePath = '@ns/prefix/resources';
$this->depends = [
CpAsset::class,
];
$this->js = [
'custom-scripts.js',
];
$this->css = [
'custom-styles.css',
];
within the init function? Is this enough to get those files onto the frontend loads or do I need something else and something to tell them not to load onto backend pages?
Thank you for any help. Most of my plugin knowledge is based on reverse engineering plugins and in this area I'm still confused.