How can I check whether there is a bootstrap.js loaded on page (a file bootstrap.js may be compiled into another big JS file)?
You can retrieve <script>
elements and check their src attribute but as you pointed out, what you are looking for is the code itself and not a file name as the code may be in any file.
The best way to detect if a JavaScript service/class/etc. is loaded in a page, is to look for something in the DOM that you know is loaded by the given JS.
E.g. to detect if jQuery is loaded, you can do null !== window.jQuery
or to find out the version of the loaded jQuery, jQuery.prototype.jquery
I would rather check for specific bootstrap plugin since modal or tooltip are very common, so
if(typeof($.fn.popover) != 'undefined'){
// your stuff here
}
or
if (typeof $.fn.popover == 'function') {
// your stuff here
}
works in both bootstrap versions
Add the bootstrap link and notice the change in h1 tag.