Forums › Forums › Search & Filter Pro › Suggestion: only load js and css when S&F is in use
- This topic has 1 reply, 2 voices, and was last updated 5 years, 10 months ago by
Ross.
-
Anonymous(Private) June 7, 2019 at 10:00 am #213533
We’ve been using Search & Filter Pro and noticed it always loads Javascript and CSS files even when Search & Filter is *not* used. This has a negative impact on the performance due to needlessly loading an extra (roughly) 110KB of data (although this will be cached after the initial load).
In your FAQ you mention a possible solution which is not adhering to best practices used in WordPress Core nor plugins in the larger WordPress ecosystem.
Your current implementation always loads the files even when not needed. Please consider refactoring your code and make your js & css files load conditionally (thus *only* add 110KB of data when needed).
If you are open to this suggestion we are willing to help with this and provide patches to realize this change, please let us know.
Kind regards,
Björn WijersRoss Moderator(Private) June 7, 2019 at 10:29 am #213536Hi 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
-
AuthorPosts