我正在尝试尽快制作我的角度网络应用。如果我从包含脚本级别开始,这就是直接实现的样子:
<!DOCTYPE html>
<html ng-app="buzz">
<head lang="en">
<meta charset="UTF-8">
<title>Live!</title>
<script type="text/javascript" src="includes/angular.js" ></script>
<script type="text/javascript" src="includes/angular-route.js" ></script>
</head>
<body ng-controller="AdminController">
<p>Hello world!</p>
<script src="includes/modules/buzz.js"></script>
<script src="includes/controllers/AdminController.js"></script>
</body>
</html>
在此处参考信息后:Where should I put <script> tags in HTML markup?
我意识到我应该制作我的脚本async
,但如果我做了以下
ReferenceError: angular is not defined buzz.js:6:4
TypeError: angular is undefined angular-route.js:24:4
ReferenceError: angular is not defined AdminController.js:5:0
这让我意识到,即使在head标签中的脚本加载之前,body标签内的脚本也开始执行。所以现在我修改了它如下:
<!DOCTYPE html>
<html ng-app="buzz">
<head lang="en">
<meta charset="UTF-8">
<title>Live Hockey Commentary!</title>
<script type="text/javascript" src="includes/angular.js" ></script>
<script type="text/javascript" src="includes/angular-route.js" ></script>
</head>
<body ng-controller="AdminController">
<p>{{data}}</p>
<script src="includes/modules/buzz.js" defer></script>
<script src="includes/controllers/AdminController.js" defer></script>
</body>
</html>
我不能async
我的模块和控制器,因为存在依赖关系。但是这不会让我的网页变得非常快吗?我无法在<head>
中同步我的角度脚本。如何尽可能快地制作我的角度网页?
在任何地方添加defer
是否会让它变得更好?