Conditional Loading is the process of loading your resources only when they are needed. For instance, bbPress loads its CSS and JavaScript on every page. However, you don’t need it on every page and if you open up your chrome developer tools (F12) then click on audits. Select Audit Present State and it will give a basic performance audit for your website.

You will likely notice remove unused CSS rules, this is a warning because the extra CSS rules are loading on a page even when they are not needed. You won’t be able to remove all of them because it would be extremely complex to do something such as that and you would likely need to build a theme from scratch with a unique CSS file for each page/widget and then combine them. However, you can remove a decent chunk of these through the use of conditional loading.

Before we start let’s point out why this matters. Most people would argue it’s better to include everything on one page and cache it so each subsequent page load would be faster. For desktop computers, this remains true except it’s not quite that simple. Many plugins already conditionally load CSS and JavaScript, some page types have different inline CSS and JavaScript. Mobile devices especially can’t handle the overhead of additional and useless CSS/JavaScript files on every single page.

Conditionally Loading bbPress

bbPress loads a couple CSS/JavaScript files on every page on the entire website. However, this is a lot of wasted bytes and you can reduce the load time for your users by conditionally loading bbPress only on bbPress and BuddyPress pages. Below is the code example to only load bbPress related scripts/styles on their respective pages.

Conditionally Loading BuddyPress

BuddyPress while important for running a community loads a ton of junk on every page load that you can really begin to slow your website down. With a quick edit your functions.php they can all be hidden from everyone else.

Concluding Thoughts

As you can see its fairly easy to reduce the amount of scripts on every load and while combining all the scripts as efficient you really want to squeeze out all the performance you can by using these tips with a plugin like Autoptimize. If you have any questions feel free to ask us here or go to our support forums and we can address them!