问题
I'm using summernote as my web online editor. But some part of the editor(buttons with bootstrap dropdown class) didn't work. I finally found out that loading jquery.js and bootstrap.js twice times was the problem (The page includes header.php which already loads the two js files). So I'm confused about the error. What would happen if a js file is loaded multiple times while some other js files depend on it? And why should jquery.js, jquery-ui.js and bootstrap.js be loaded in order when they are downloaded in parallel?
回答1:
Good question. The reason that this is happening is because the editor that you are using already contains loaded libraries of those two files as is. When you added them what happened was is they overrode the first files that were pre-loaded; that reset several key variables within the window. Since they were reset, things that made your editor work properly failed, causing a domino effect and crashing your program.
EDIT: I also was reading up more about this subject because it was interesting to me. There are some circumstances in which multiple versions of jQuery are loaded into a document. An example is if there was a set of functions that was depreciated from one version to the next, and you found them useful, this is a valid reason to have two files. In that instance you would want to use noConflict from one library to another, in order to keep the scripting inline, and not have them confuse eachother, a quick reference example below:
<script src="other_lib.js"></script>
<script src="jquery.js"></script>
<script>
$.noConflict();
// Code that uses other library's $ can follow here.
</script>
Also, if you want to read up more about the functionality of noConflict(), here is a good reference link for you:
http://api.jquery.com/jquery.noconflict/
To sum everything up though, I would avoid using multiple libraries that are the same version completely. Also to help you avoid this in the future, if you're just starting out and only using javascript, html, and css, I would recommend a text editor. This was you know what your environment you are working with is, and it allows you total control. Here's a link to a good one:
Sublime Text: http://www.sublimetext.com/
来源:https://stackoverflow.com/questions/25996191/why-loading-bootstrap-js-twice-times-results-to-an-error