PDA

View Full Version : Conditional plugin loading - good idea or not?



Ironwil
01 Aug 2012, 01:40 PM
I'm wondering of the pros and cons of setting up a conditional plugin loading script for my pages. Basically it would look a bit like this:



function init(){
if($(".accordion").length > 0) {
// run accordion plugin init code;
}
}


I'm trying to put together a really convenient starting template for building websites. I'm currently working with H5BP combined with the Skeleton responsive template. I usually work with ASP.NET MVC 3, so I've created a project template with these, along with Squi**** and the free version of Mindscape Web Workbench. The Workbench extension allows me to work with SASS, and Squi**** minifies and combines the CSS and JavaScript files when the project is run. So far I'm pretty happy with it, but it's a minimal starting point, of course. I'd also like to include as partial views a base version of the free jQuery plugins I like to use. Instead of having scripts in these views (except to override defaults), I'd like to have the conditional loading script I mentioned above. I'm just not sure of the performance ramifications. Any advice?

The foul language parser mistook my reference above for a curse word. Split into two words to keep the parser happy, it's supposed to read Squish It.