Some plugins I use (I think about Events and Lightslider especially) are not needed in every page, but their css and js are always loaded. It makes some pages unnecessarily heavy and I would like to avoid that by loading these plugins only on some pages with specific templates.
I imagine it’s not so difficult to achieve in php, but I’m not familiar with this language and I haven’t tried to dig into php files so far… could someone help me with that?
@jordan ,
yes, your idea of loading assets only on the pages where needed via template is right.
all you have to do is writing the correct template.
as an example, you can take this template as a reference.
no PHP expertise needed here
ah, yes, of course the mechanism of loading assets is unique to each plugin, and, @anon76427325 you are right in that my suggestion would not work with the mentioned plugins without changes to the plugin’s php source.
my intention was rather to provide an example how to do this.
so the OP could
create an issue as @Karmalakas proposed
or
adapt the beforementioned plugins and create a pull request
Thanks for your answers.
I will create an issue for the plugins concerned. And in the meantime I’ll have to modify the plugin’s php file by adding a condition to the loading of the assets.
That’s what I’ve done for the plugin event and it does the job. In the public function onTwigSiteVariables() of the file events.php, it looks like this