Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

javascript - HTML5 Boilerplate plugins.js

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...