Give
Conditionally Load GiveWP Styles and Scripts
Some developers put a lot of attention into which styles and scripts are loaded on each page of their site. This article explains how to conditionally load the GiveWP styles and scripts and explains a little why we’ve chosen not to do this by default.
Some developers put a lot of attention into which styles and scripts are loaded on each page of their site. This article explains how to conditionally load the GiveWP styles and scripts and explains a little why we’ve chosen not to do this by default.
Pros and Cons of Conditionally Loading Styles and Scripts
While in theory it sounds very beneficial to only load GiveWP styles and scripts when they are actually used on a page or post, in practice this often ends up creating more trouble than benefit. We have chosen to load all our GiveWP styles and scripts minified and concatenated into one file each and have that load throughout the site.
The main reason we’ve chosen to do that is because very many WordPress sites use some sort of minification and/or caching plugin to concatenate and minify all the scripts and styles of the entire site into one large file or perhaps up to 4 smaller files each. When different scripts and styles are loaded conditionally on different pages/posts the results are often very mixed whether the conditionally loaded scripts will be minified correctly and applied correctly when needed.
Nevertheless, we wanted to provide a method for developers to conditionally load scripts with GiveWP regardless.
A Note on Debugging
If you have WP_DEBUG set to true, then GiveWP will load all of its scripts individually throughout your site and the above function will not work at all. This only applies to the minified and concatenated style and script: give.min.css and give.all.min.js which are only loaded when WP_DEBUG set to false.