32

How is one expected to include additional js files in plugins.js? Is the expectation that we just copy and paste the contents of each plugin there? Or is there some method of doing a js include that I should be using?

Specifically, I'd like to see an example of goes within this function:

// remap jQuery to $
(function($){

})(this.jQuery);
casperOne
  • 73,706
  • 19
  • 184
  • 253
Matrym
  • 16,643
  • 33
  • 95
  • 140
  • There is a nice boilerplate to follow here: http://www.websanova.com/tutorials/jquery/jquery-plugin-development-boilerplate – ROb Mar 28 '12 at 01:37
  • link to websanova in previous comment is broken – Steve Dec 03 '22 at 12:11

1 Answers1

33

That section of the html5boilerplate is sort of an abbreviation of what should/could go there.

You can approach plugins.js a few ways:

  1. Ignore it and include all of your JS plugins as separate files (undesirable)
  2. Manually concatenate and minify the plugin files (this is a pain to maintain)
  3. Use a script to concatenate them (and cache it) at run-time (like this)
  4. Use a makefile to concatenate/compress like a ninja (like this)
  5. Use a slick JS library like yepnope.js to asynchronously load your plugin files as needed.

There's a lot of options for including your JS plugins...you'll have to weigh them yourself, of course. I usually use options 3 or 4, though I need to start using 5.

As for what goes in the snippet of code that you gave:

(function($){
  // This is a wrapper for your jQuery stuff 
})(this.jQuery);

You'll see that block of code wrapping a lot of jQuery plugins (check the docs). It can be used to wrap your jQuery-specific code so you can make use of $ while keeping your site in jQuery compatibility mode...which lets your site play nicely with other libraries that may use $ as well.

borkweb
  • 1,014
  • 7
  • 7
  • Yeah, I think the purpose of the plugins file it just to have a place where you put your jQuery plugin code so it doesn't polute the global namespace. – Gabriel Jan 01 '11 at 00:06
  • 5
    So what's the point of the "mylibs" directory? I'm surprised H5B doesn't go into more detail on how to use jQuery plug-ins with it and give better examples. – Cofey Feb 12 '11 at 02:08
  • 1
    What borkweb says. The [FAQs](https://github.com/paulirish/html5-boilerplate/wiki/FAQs) cover it as well. – Divya Manian Jan 02 '11 at 17:18
  • Here is a more [detailed explanation of plugins.js and scripts.js](http://html5boilerplate.com/html5boilerplate-site/built/en_US/docs/js/) though it might be slightly dated. – skube Apr 25 '13 at 15:34
  • Note that H5BP comes with Modernizer by default. Modernizer comes with yesnope.js embedded by default. So you shouldn't need to load yesnope separately. http://modernizr.com/docs/#load – skibulk Oct 02 '14 at 17:54