[Plugin: NextGEN Scroll Gallery] Scripts loaded on all pages
-
Hi. This is just a topic with the intention of notifying users, and hopefully aiding the development of this plugin.
I am the creator of a plugin, the Riva Slider Pro (http://rivaslider.com/), which allows users to easily create slideshows that utilize jQuery. Quite a few users have notified me of issues they are having when NextGEN Scroll Gallery is enabled.
The jQuery script for my slideshow uses the jQuery ‘load’ function as a part of a preloader that loads the images before displaying them. I am aware that NextGEN Scroll Gallery uses MooTools and loads it on every page. This appears to be breaking the functionality and causing problems.
The problem is that MooTools has its own ‘load’ function. This function also gets triggered whenever a jQuery script uses ‘load’, giving the browser a heart attack and making it crash in most cases (Firefox is the worst victim). It also breaks jQuery completely.
NextGEN Scroll Gallery really creates problem because it loads its scripts on all pages, even when a Scroll Gallery is not being used. I think it would be a great idea to conditionally load the scripts in the pages footer instead. This would allow the scripts to only be loaded on pages that a Scroll Gallery is used, and not elsewhere.
This would mean that users who have plugins that use jQuery (which a lot do) can be free from MooTools conflictions, such as the one above. It would also greatly reduce the amount of files loaded unnecessarily.
This would also be great to prevent problems with any other plugins, and probably free up some support time (and the numbers of support requests).
Conditionally loading scripts can be quite tricky to do, but with a plugin like this that is quite popular I think it would be a great idea. Below is a snippet of code that should the ball rolling.
// This function registers the scripts to be loaded in the footer function plugin_register_scripts() { global $scripts_loaded; if ( !is_admin() && $scripts_loaded == false ) { wp_register_script( '.. your script ..', ' .. script URL .. ' ), false, null, true ); // Tell other functions that the script has been registered $scripts_loaded = true; } } // This function prints the scripts in the footer function plugin_footer_scripts() { global $scripts_loaded; // If scripts have been registered, print them. if ( $scripts_loaded == true ) { if ( wp_script_is( '.. your script to enqueue ..' , 'queue' ) == false ) wp_print_scripts( '.. your script to enqueue ..' ); } } add_action( 'wp_footer', 'plugin_footer_scripts' );The above code would register the scripts, and then load them in the footer. For this to be put into action, you would have to call the ‘plugin_register_scripts’ function within the function you use to display a Scroll Gallery. Simply add the code below to the Scroll Gallery function.
if ( function_exists( 'plugin_register_scripts' ) ) plugin_register_scripts();Anyway, that is it really. I just thought I’d put it out there. This post may also help users who want to conditionally load scripts, as well as troubleshoot issues they may be having between your plugin and other jQuery based plugins.
The topic ‘[Plugin: NextGEN Scroll Gallery] Scripts loaded on all pages’ is closed to new replies.