简体   繁体   English

执行<script> tag out of <head> in angularjs

[英]Execute <script> tag out of <head> in angularjs

I have this quite old angularjs project without npm dependencies and all of them are inside the head tag in the index.html just like so:我有这个相当老的 angularjs 项目,没有 npm 依赖项,它们都在 index.html 的 head 标签内,就像这样:

<head>
<meta charset="utf-8">
<meta http-equiv="Cache-control" content="max-age=0"/>
<meta http-equiv="Cache-control" content="no-cache"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<!-- STYLES -->
<link rel="stylesheet" href="dist/css/styles.css">

<!-- SCRIPTS -->
<script src="dist/js/application/angular.min.js"></script>
<script src="dist/js/application/angular-touch.min.js"></script>
<script src="dist/js/application/angular-route.min.js"></script>
<script src="dist/js/application/angular-resource.min.js"></script>
<script src="dist/js/application/angular-sanitize.min.js"></script>
<script src="dist/js/application/angular-translate.min.js"></script>
</head>

Now I am required to add an extra dependency called iframeResizer.contentWindow.min.js which requires to be at the end of the body tag.现在我需要添加一个名为iframeResizer.contentWindow.min.js的额外依赖,它需要位于 body 标签的末尾。 But when I add it like this:但是当我像这样添加它时:

<script src="dist/js/application/iframeResizer.contentWindow.min.js"></script>

it appears in the DOM but it is not called in the Network tab if I put it there.它出现在 DOM 中,但如果我将它放在那里,则不会在“网络”选项卡中调用它。 Dependency shown at the DOM DOM 中显示的依赖关系DOM 中显示的依赖关系

网络选项卡中缺少依赖项

What am I missing here?我在这里缺少什么? Does AngularJS have a custom way to manage these dependencies? AngularJS 是否有自定义的方式来管理这些依赖项? How can I make it work?我怎样才能让它工作?

One simple workaround would be to put it in head and to replace一种简单的解决方法是把它放在头上并替换

<script src="dist/js/application/iframeResizer.contentWindow.min.js"></script>

By经过

<script src="dist/js/application/iframeResizer.contentWindow.min.js" defer></script>

This way even if in <head> it would be called after page load !这样即使在<head>它也会在页面加载后调用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM