角度2:慢吗?

Angular2: Is it slow?

本文关键字:慢吗 角度      更新时间:2023-09-26

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

在那里,他们有一个 5 分钟的快速入门项目,该项目快速显示了新语法以及执行新角度应用程序必须使用的内容。

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

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

这是我的代码

// 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);

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>
  • 您正在使用 RTTS(运行时类型系统检查)运行它非常适合开发,但对于生产来说速度很慢
  • 我们尚未将所有文件连接成单个文件以进行快速加载。
  • 我们仍然有慢速变化检测,因为快速变化检测尚未在 Dart 中工作,我们希望保持一致。

请参阅 https://github.com/djsmith42/angular2_calendar 了解如何使其快速运行。

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

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

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

换句话说,一旦前期大热门完成,它就可以非常快,最重要的是,非常高效。

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