javascript Angular2:慢吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28926666/
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-10-28 09:46:11  来源:igfitidea点击:

Angular2: Is it slow?

javascriptgoogle-chromeangular

提问by Alejandro Garcia Anglada

Just took a look at the last angular version that the angular team launch. Angular2 is out and they have been release a their new webpage https://angular.io.

看看 angular 团队推出的最后一个 angular 版本。Angular2 出来了,他们已经发布了他们的新网页https://angular.io

In there they have a 5 min quickstart project that shows quickly the new syntax and what you have to use to perform a new angular application.

在那里,他们有一个 5 分钟的快速入门项目,可以快速显示新语法以及您必须使用什么来执行新的 Angular 应用程序。

I just did all the steps to get it working but it took 4.93 seconds to load.

我只是做了所有的步骤来让它工作,但加载需要 4.93 秒。

I'm just wondering, is angular 2 that slow? Or maybe I miss some steps.

我只是想知道,angular 2 这么慢吗?或者也许我错过了一些步骤。

Here is my code

这是我的代码

// app.es6

import { Component, Template, bootstrap } from "angular2/angular2";

// Annotation section
@Component({
  selector: "my-app"
})
@Template({
  inline: "<h1>Hello {{ name }}</h1>"
})
// Component controller
class MyAppComponent {
  constructor() {
    this.name = "Alex!";
  }
}

bootstrap(MyAppComponent);

and index.html

index.html

<!-- index.html -->
<html>

<head>
    <title>Angular 2 Quickstart</title>
    <script src="dist/es6-shim.js"></script>
</head>

<body>

    <!-- The app component created in app.js -->
    <my-app></my-app>

    <script>
        // Rewrite the paths to load the files
          System.paths = {
            'angular2/*':'angular2/*.js', // Angular
            'rtts_assert/*': 'rtts_assert/*.js', //Runtime assertions
            'app': 'app.js' // The my-app component
          };

          // Kick off the application
          System.import('app');
    </script>
</body>

</html>

回答by Misko Hevery

  • You are running with RTTS (run-time type system checks) It is great for development, but slow for production
  • We have not concatenated all the files into single file for fast loading.
  • We still have the slow change detection, since the fast one is not yet working in Dart, and we want to be consistent.
  • 您正在使用 RTTS(运行时类型系统检查)运行这对开发非常有用,但对生产来说很慢
  • 我们没有将所有文件连接成单个文件以进行快速加载。
  • 我们仍然有慢变化检测,因为快速检测在 Dart 中还没有工作,我们希望保持一致。

See https://github.com/djsmith42/angular2_calendaron how to get it to run fast.

有关如何使其快速运行,请参阅https://github.com/djsmith42/angular2_calendar

回答by Greg Woods

Yes, a page written using angular2 is slow.

是的,使用 angular2 编写的页面很慢。

I'm not saying the angular2 code is slow (I wouldn't dare), just that the simplest page you can write using angular will load in 5 seconds or more. There are a LOT of files which need to be loaded. It's true that you can make this faster by combining files so you get fewer http requests, and being careful about not loading stuff you are not using, but it is never going to be fast like a simple html + js page.

我并不是说 angular2 代码很慢(我不敢),只是您可以使用 angular 编写的最简单的页面将在 5 秒或更长时间内加载。有很多文件需要加载。确实,您可以通过组合文件来加快速度,从而减少 http 请求,并注意不要加载您不使用的内容,但它永远不会像简单的 html + js 页面那样快。

It is important to remember though, that angular is designed for single page apps. All the dependencies load once, in a single index file, and from then on, the angular routing allows you to navigate to different "pages", which are really just template files.

但重要的是要记住,angular 是为单页应用程序设计的。所有依赖项在单个索引文件中加载一次,从那时起,角度路由允许您导航到不同的“页面”,这些页面实际上只是模板文件。

In other words, once the big upfront hit is done, it can be really fast, and most importantly, very productive.

换句话说,一旦完成了重大的前期工作,它就会变得非常快,最重要的是,非常高效。

回答by user2379441

If you follow the QuickStart tutorial line by line if for the latest version alpha27, it's going to be dead slow as the System.js and angular2.min.js file takes ages to load. Better is if you can use our own server to host them. Moreover, from your code you seem to be using a pre-alpha20 codebase. Upgrade to alpha27, it's a hell lot faster.

如果对于最新版本的 alpha27 逐行遵循 QuickStart 教程,它将会非常缓慢,因为 System.js 和 angular2.min.js 文件需要很长时间才能加载。更好的是,如果您可以使用我们自己的服务器来托管它们。此外,从您的代码来看,您似乎正在使用 pre-alpha20 代码库。升级到 alpha27,速度要快得多。