Hi Bjorn
S&F already has this option – check settings
-> lazy load Javascript
This means, JS will not be loaded until a search form is present on the page somewhere.
However, with CSS, this is not strictly possible.
CSS should be loaded in the head of a page, however, sometimes we do not know if a page contains a search form, until some of the body (ie, on of our shortcodes) has already been printed… which means its not possible (whilst keeping to standards) to conditionally load our CSS, unless we want to print it inline.
My recommendation is to enable lazy load Javascript
, and then conditionally unload our CSS, based certain rules so you know it only shows it on the page with the search form on.
As far as I’m aware, this is not considered bad practice – if you can share any better methods / logic of approaching this I’d be happy to hear 🙂
Thanks