为什么在科尔多瓦针对Windows 8时,WInJS自动包含? [英] Why is WInJS included automatically when targeting Windows 8 in Cordova?

查看:178
本文介绍了为什么在科尔多瓦针对Windows 8时,WInJS自动包含?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发使用AngularJS一个应用程序,而当我们针对Windows 8我注意到,生成的Visual Studio项目包括WinJS作为参考。因为我们没有使用WinJS我只是删除了该项目的参考。

We're developing an app using AngularJS, and when we're targeting Windows 8 I noticed that the generated Visual Studio project included WinJS as a reference. Since we're not using WinJS I simply removed the reference from the project.

然后我注意到,取消WinJS运行应用程序时引起了控制台良性脚本加载错误。进一步的调查表明, cordova.js 自动检查为WinJS,并且如果不包括尝试包括它(!)。下面是相关的code:

Then I noticed that removing WinJS caused benign script load errors in the console when running the app. Further investigation showed that cordova.js automatically checks for WinJS, and if not included tries to include it (!). Here's the relevant code:

var onWinJSReady = function () {
    var app = WinJS.Application;
    var checkpointHandler = function checkpointHandler() {
        cordova.fireDocumentEvent('pause',null,true);
    };

    var resumingHandler = function resumingHandler() {
        cordova.fireDocumentEvent('resume',null,true);
    };

    app.addEventListener("checkpoint", checkpointHandler);
    Windows.UI.WebUI.WebUIApplication.addEventListener("resuming", resumingHandler, false);
    app.start();
};

if (!window.WinJS) {
    var scriptElem = document.createElement("script");

    if (navigator.appVersion.indexOf("Windows Phone 8.1;") !== -1) {
        // windows phone 8.1 + Mobile IE 11
        scriptElem.src = "//Microsoft.Phone.WinJS.2.1/js/base.js";
    } else if (navigator.appVersion.indexOf("MSAppHost/2.0;") !== -1) {
        // windows 8.1 + IE 11
        scriptElem.src = "//Microsoft.WinJS.2.0/js/base.js";
    } else {
        // windows 8.0 + IE 10
        scriptElem.src = "//Microsoft.WinJS.1.0/js/base.js";
    }
    scriptElem.addEventListener("load", onWinJSReady);
    document.head.appendChild(scriptElem);
}
else {
    onWinJSReady();
}

我想我的主要问题是,我应该离开WinJS引用按原样,让科尔多瓦加载并初始化WinJS?

难道可能与AngularJS冲突或减少以任何方式应用程序的性能?
(我猜 VAR应用= WinJS.Application app.start() onWinJSReady 让我有点担心)。

Could it potentially conflict with AngularJS or reduce the performance of the app in any way? (I guess var app = WinJS.Application and app.start() in onWinJSReady makes me a bit worried).

由于应用程序似乎没有WinJS脚本文件做工精细,为什么cordova.js在试图将其纳入这样坚持?

Since the app seems to work fine without the WinJS script files, why is cordova.js so insistent on trying to include it?

推荐答案

科尔多瓦(和一些插件科尔多瓦,尤其是文件系统插件)使用WinJS的某些功能,如承诺与Ajax调用。我们结束了分叉cordova.js和剥离了所有的WinJS东西...使应用程序加载速度快了很多!

cordova (and some cordova plugins, particularly the FileSystem plugin) use some features of WinJS, such as Promises and Ajax calls. We ended up forking cordova.js and stripping out all the WinJS stuff... makes the app load a lot faster!

这篇关于为什么在科尔多瓦针对Windows 8时,WInJS自动包含?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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