如何停止两次Knockout 3.2库加载 [英] How to stop Knockout 3.2 library loading twice

查看:115
本文介绍了如何停止两次Knockout 3.2库加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到绑定表达式的问题,例如

I have the issue that binding expressions such as

<div data-bind="text: $data.Property"></div>

-where Property 是一个可观察的原因要显示的敲除的可观察函数的实际文本而不是值属性应该代表。这是在这里解决的在IE8中,KnockoutJS 3.2显示实际的可观察函数而不是observable的值

-where Property is an observable- causes the actual text of knockout's observable function to display instead of the value Property is supposed to represent. This was addressed here In IE8, KnockoutJS 3.2 displaying actual observable function rather than the observable's value.

该问题的原因是正在加载重复的淘汰库文件。 更新:部分和链接的SO问题的答案包括一些细节。

The cause of that issue was that duplicate knockout library files were being loaded. The "UPDATE:" section and answer of the linked SO question includes some detail around that.

我现在需要知道如何防止敲除库被加载两次。 强调已加载而不仅仅是执行。到目前为止,我还没有找到任何可以解决此问题的内容。

I now need to know how to keep the knockout library from being loaded twice. Emphasis on loaded not just executed. So far I haven't found anything that quite answered this.

RequireJS :由网站使用,但不是由调查页面使用。

RequireJS: is used by the site but, not by the pages under investigation.

SignalR:由页面使用。我对SignalR有点不熟悉,所以我不能说这会导致多次加载的可能性。

SignalR: is used by the page. I'm a bit unfamiliar with SignalR so I can't say how likely it is that this is causing multiple loads.

Ajax:也被使用但是它被使用了接收JSON数据。

Ajax: is used as well but it is used to receive JSON data.

只有1个明确引用的淘汰库。

There is only 1 explicit reference to the knockout library.

查看网络选项卡,第一个文件是从推测性下载功能。第二个文件来自主解析器。第一个文件已完全下载,然后第二个文件已完全下载。

Looking at the network tab, the first file is loaded from the speculative download feature of IE. The second file is from the main parser. The first file is completely downloaded, and then the second is completely downloaded.

我无法弄清楚的是一种保留方式:

What I haven't been able to figure out is a way to keep:


  • 第一次下载文件的Lookahead Downloader

  • 第二次下载文件的主解析器

  • 第二次执行文件而不更改库文件中的代码。

在这一点上,上述解决方案之一是可以接受的。任何人都可以提供见解,建议或知道解决方案吗?

One of the above solutions can be acceptable at this point. Can anyone offer insight, suggestions or know of a solution to this?

推荐答案

我终于搞清楚了。问题是脚本在页面中列出的顺序。 ASP.NET MVC 5支持可渲染的命名部分。在这种情况下脚本

I finally got this figured out. The issue was the order that the scripts were listed in the page. ASP.NET MVC 5 supports renderable named sections. In this case scripts:

布局 -

@RenderSection("scripts", required: false)

views /部分视图 -

Views/Partial Views -

@section scripts {
    // script includes ...
}

在我的情况下,部分视图不包含脚本中的脚本部分导致prearser和主解析器解析/下载它们。

In my case a partial view did not include scripts in a scripts section causing them to be parsed/downloaded by the preparser and the main parser.

将所有脚本添加到脚本正确顺序的部分解决了这个问题。订单已由脚本的依赖项决定。

Adding all scripts to scripts sections in the proper order solved this problem. The order has been determined by the the scripts' dependencies.

这篇关于如何停止两次Knockout 3.2库加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆