{"record":{"id":"f033cb97f0e4d521","repo":"dotnet/AspNetCore.Docs","slug":"bootstrap-s-javascript-requires-jquery","errorCode":null,"errorMessage":"Bootstrap's JavaScript requires jQuery","messagePattern":"Bootstrap's JavaScript requires jQuery","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"aspnetcore/mvc/controllers/testing/samples/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/bootstrap.js","lineNumber":8,"sourceCode":"/*!\n * Bootstrap v3.3.7 (http://getbootstrap.com)\n * Copyright 2011-2016 Twitter, Inc.\n * Licensed under the MIT license\n */\n\nif (typeof jQuery === 'undefined') {\n    throw new Error('Bootstrap\\'s JavaScript requires jQuery')\n  }\n  \n  +function ($) {\n    'use strict';\n    var version = $.fn.jquery.split(' ')[0].split('.')\n    if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] > 3)) {\n      throw new Error('Bootstrap\\'s JavaScript requires jQuery version 1.9.1 or higher, but lower than version 4')\n    }\n  }(jQuery);\n  \n  /* ========================================================================\n   * Bootstrap: transition.js v3.3.7\n   * http://getbootstrap.com/javascript/#transitions\n   * ========================================================================\n   * Copyright 2011-2016 Twitter, Inc.\n   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n   * ======================================================================== */\n  ","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/mvc/controllers/testing/samples/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/bootstrap.js#L1-L26","documentation":"The first line of Bootstrap 3.3.7's bootstrap.js checks `typeof jQuery === 'undefined'`. Bootstrap's plugins all wrap `+function($){...}(jQuery)` and need jQuery present at load time. If jQuery is missing or loaded after bootstrap.js, the file fails fast on parse. This is a hard prerequisite guard.","triggerScenarios":"Including bootstrap.js without jQuery; jQuery included after bootstrap.js; jQuery blocked by a script error or CSP; bundle minification dropping jQuery.","commonSituations":"_Layout.cshtml script ordering; deferred/async script tags reordering execution; ASP.NET Core bundling misconfiguration; CDN jQuery failing to load (404).","solutions":["Include jQuery before bootstrap.js in the HTML.","If using a CDN, add a local fallback: <script>window.jQuery || document.write('<script src=\"lib/jquery\"><\\/script>')</script>.","Check the bundling pipeline output to confirm jQuery is emitted first.","Ensure no script errors earlier in the page aborted jQuery's load."],"exampleFix":"// before\n<script src=\"bootstrap.js\"></script>\n<script src=\"jquery.js\"></script>\n// after\n<script src=\"jquery.js\"></script>\n<script src=\"bootstrap.js\"></script>","handlingStrategy":"validation","validationCode":"// Verify jQuery is present before loading Bootstrap-dependent code.\nfunction ensureJQuery() {\n  if (typeof window.jQuery === 'undefined') {\n    throw new Error('jQuery not loaded; include it before bootstrap.js');\n  }\n  return window.jQuery;\n}\nvar $ = ensureJQuery();\n// then it is safe to reference bootstrap.js","typeGuard":"function jQueryReady() { return typeof window !== 'undefined' && typeof window.jQuery === 'function'; }","tryCatchPattern":"// The throw happens at script parse; wrap the bootstrap include so a CDN failure is visible.\nwindow.addEventListener('error', function (ev) {\n  if (ev && /Bootstrap.*requires jQuery/.test(ev.message || '')) {\n    console.error('jQuery failed to load before bootstrap.js');\n  }\n}, true);","preventionTips":["Put jQuery first in the layout script block, then Bootstrap.","Add a local fallback after a jQuery CDN include.","Verify bundling emits jQuery before Bootstrap in the minified output."],"tags":["bootstrap","jquery","load-order","script-tags","dependency"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}