jQuery 未呈现捆绑脚本文件。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14365673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:30:20  来源:igfitidea点击:

Bundle script file not being rendered.

jqueryasp.net-mvcresourcebundle

提问by Bilal Fazlani

Script file name:

脚本文件名:

jquery.transit.min.js

The file is in the Scripts folder,

该文件位于 Scripts 文件夹中,

bundles.Add(new ScriptBundle("~/bundles/jquery")
       .Include("~/Scripts/jquery-{version}.js"));

bundles.Add(new ScriptBundle("~/bundles/jqueryui")
       .Include("~/Scripts/jquery-ui-{version}.js"));

bundles.Add(new ScriptBundle("~/bundles/jqueryval")
       .Include("~/Scripts/jquery.unobtrusive*", "~/Scripts/jquery.validate*"));

bundles.Add(new ScriptBundle("~/bundles/jtransit")
       .Include("~/Scripts/jquery.transit*"));

In my View,

在我的View,

@Scripts.Render("~/bundles/jquery","~/bundles/jtransit")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/jqueryval")

Rendered HTML

渲染 HTML

<script src="/Scripts/jquery-1.8.3.js"></script>
<script src="/Scripts/jquery-ui-1.9.2.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

jquery.transit.min.jsdoesn't get rendered. What am I missing?

jquery.transit.min.js不会被渲染。我错过了什么?

回答by ngm

I think it will be because you only have the .min version of your file.

我认为这是因为您只有 .min 版本的文件。

From your output I can see that you are running the debug build of your site. I guess as such the bundler is looking for a non-minified file.

从您的输出中,我可以看到您正在运行站点的调试版本。我猜因此打包程序正在寻找一个非缩小的文件。

If you were to do a Release build, then it would be bundled in OK.

如果您要进行 Release 构建,那么它将被捆绑在 OK 中。

I'd suggest getting a non-minified version of the transit file and including that in your Scripts folder. Failing that, just make a copy of the minified version but without the .min in the filename.

我建议获取传输文件的非缩小版本,并将其包含在您的 Scripts 文件夹中。如果失败,只需制作缩小版本的副本,但文件名中没有 .min。

回答by rae1

Starting in MVC4, any minimized version of your JavaScript files or CSS files are ignoredin Debug mode. As ngm suggests, you need to rename your file from,

从 开始MVC4,任何最小化版本的 JavaScript 文件或 CSS 文件在调试模式下都将被忽略。正如 ngm 所建议的,您需要重命名您的文件,

jquery.transit.min.js

to,

到,

jquery.transit.js

Alternatively, you could modified the bundles.IgnoreListto allow minimized files to be rendered, as shown here.

或者,你可以修改bundles.IgnoreList,以允许最小的文件被渲染,如图所示这里

回答by Daniel

I had to do this in Application_Start:

我必须在 Application_Start 中执行此操作:

BundleTable.EnableOptimizations = true;

回答by R. Schreurs

In my case, I was attempting to use a script bundle and a style bundle with the same name.

就我而言,我试图使用同名的脚本包和样式包。

BundleConfig.cs:

捆绑配置.cs:

bundles.Add(new ScriptBundle("~/bundles/custom")
    .Include("~/Scripts/custom.js"));

bundles.Add(new StyleBundle("~/bundles/custom")
    .Include("~/CSS/custom.css"));

_Layout.cshtml:

_Layout.cshtml:

@Scripts.Render("~/bundles/custom")
@Styles.Render("~/bundles/custom")

This doesn't work. The last bundle added in the config survives, and @Scripts.Render("~/bundles/custom")just renders an empty line.

这不起作用。配置中添加的最后一个包仍然存在,并且@Scripts.Render("~/bundles/custom")只呈现一个空行。

I am using MVC 5.2.3.

我正在使用 MVC 5.2.3。

回答by dim_user

If none of the above questions resolve your problem maybe you're missing this line

如果上述问题都不能解决您的问题,那么您可能错过了这一行

BundleConfig.RegisterBundles(BundleTable.Bundles);

from the Global.asax.cs file, if you're getting started with bundling take a look of this site: https://www.asp.net/mvc/overview/performance/bundling-and-minification

从 Global.asax.cs 文件,如果您开始使用捆绑,请查看此站点:https: //www.asp.net/mvc/overview/performance/bundling-and-minification

回答by Tomas Kubes

In my case Visual Studio 2013 just thought that bundling css files are missing, it showed yellow question mark over the filename in Solution Explorer.

在我的情况下,Visual Studio 2013 只是认为缺少捆绑的 css 文件,它在解决方案资源管理器中的文件名上显示黄色问号。

Just double-click all these supposedly missingfiles and Visual Studio will find them, yellow question will mark dismiss and bundling will start working again like a charm.

只需双击所有这些据称丢失的文件,Visual Studio 就会找到它们,黄色问题将标记为解除,捆绑将再次开始工作。

回答by Glade Mellor

and make sure you're not using IE 8. Bundling failed for me in that browser but works fine in Chrome or Firefox.

并确保您没有使用 IE 8。我在该浏览器中捆绑失败,但在 Chrome 或 Firefox 中运行良好。