【发布时间】:2013-07-30 18:55:20
【问题描述】:
我有一个使用 jQuery 2.0+ 的网站,如果尚未加载 jQuery,我想执行一个操作。本质上,我正在检查任何不支持 jQuery 2 的浏览器,例如 IE8、7、6 等。
我在 jquery.check.js 中就是这样做的
if (typeof window.jQuery == 'undefined') {
//show not supported page
}
BundleConfig 是这样进行捆绑的:
var b1 = new ScriptBundle("~/bundle/js").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery.check.js"
);
b1.Orderer = new InputBundleOrderer();
b1.Transforms.Clear(); //this removes the mimification for debugging purposes
bundles.Add(b1);
在debug="true" 上,代码运行良好。当转向false 时它不起作用。使用 IE8 进行调试时,永远无法到达 if 语句,并且出现一堆错误。
听起来 IE8 在发生错误时停止执行 JavaScript 文件,因此永远无法到达代码块。这是我能想到的唯一原因,为什么它在 debug="true"(文件单独加载)时有效,而在捆绑时无效(一个文件)。
我的推理正确吗?
【问题讨论】:
-
我最终通过从包中排除 jquery.check.js 并将其添加为单独的参考来解决问题。这基本上证明了我的想法是对的。
标签: jquery asp.net-mvc-4 internet-explorer-8 bundling-and-minification jquery-2.0