I'm new at this html5boilerplate and jQuery stuff, so please bear with me...

I am a starting a new project based on the H5B v4.3.0 distribution. I want to add the jQuery.form plugin, but I'm not sure where it should go and what it should look like. I see in the plugins.js file the comment saying, "Place and jQuery/helper plugins in here." But, I obviously cannot use

<script src="js/vendor/jquery.form.js"></script>

in the js file.

I have also seen a reference to RequireJS, but that looks like it is going to add way more complexity than I need right now.

Am I correct in thinking that the jquery.form load should go in plugins.js? If so, what does the command look like? If not, and it stays in the index.html, then what's up with that comment?

Thanks, Thom

OBTW, I did see another answer, but other than saying I should use

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

it doesn't give me any helpful examples. How about showing me how to put just one plugin inside that wrapper?

有帮助吗?

解决方案

Adding your plugins into plugins.js is just a recommendation. You can add you script tag to your page if you are more comfortable with that, it's up to you.

But to answer your question, the idea of the plugins.js file is to keep all your plugins in one file so it's just a single request for all your plugins instead of multiple request for a bunch of different plugins.

the best way to do this is to minify all your plugins and copy and paste that minified code into your plugins.js file separating them with relevent comments. Like so:

/*
* jQuery Form Plugin; v20140218
* http://jquery.malsup.com/form/
* Copyright (c) 2014 M. Alsup; Dual licensed: MIT/GPL
* https://github.com/malsup/form#copyright-and-license
*/
;!function(a){"use strict";"function"==typeof define& ...

/*
* Another plugin
* plugin info
*/
;!function(a){"use strict";"function"==typeof define& ...

You can use an online tool like jscompress to minify your javascript files for you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top