将外部脚本合并到Meteor中 [英] Incorporating external script into Meteor

查看:71
本文介绍了将外部脚本合并到Meteor中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Meteor中加入了一个外部主题。它在body标记结束之前加载了一些脚本。当在Meteor模板的< body> 内时,< script> 标签不起作用。

I'm incorporating an external theme into Meteor. It has some scripts loaded before the end of the body tag. The <script> tags doesn't work when inside the <body> of the Meteor template.

该主题使用了像bootstrap,jquery和其他各种外部JS库这样的js(它也放在最后,在< / body>之前; 。最后一个脚本是这个 custom.js 脚本,这是特定于主题的脚本。除了常规函数语句之外的脚本中有两个匿名函数,两个 if 在顶层阻止, $(文档).ready 回调和 $(窗口).load 回调。

The theme uses js like Bootstrap, jquery, and various other probably external JS libraries (which it also puts at the end, before the </body>. The last script is this custom.js script which is this theme-specific. Inside the script other than regular functions statements, there are two anonymous functions, two if blocks at the top level, a $(document).ready callback and a $(window).load callback.

加载脾气最少的脚本的最佳方法是什么?我试图移动Meteor模板的< head> 内的所有脚本。但是缺少一些效果。我想也许是 $(窗口).load 没有在正确的时间调用。所以我在 Template.scriptAppend.rendered 里面调用它,其中scriptAppend是模板t o在< / body> 结尾之前的部分权利。我还在 $(窗口).load 中移动了两个匿名函数和两个 if 块。它有效,但这是一个麻烦。有没有办法让脚本保持原样?

What's the best way to load the scripts with the least tempering? I tried to move all the scripts inside the <head> of the Meteor template. But some effects is missing. I think maybe the $(window).load is not getting called at the right time. So I call it inside Template.scriptAppend.rendered where scriptAppend is a template to a partial right before the end of the </body>. I also move the two anonymous functions and the two if blocks inside the $(window).load. It works but it's such a hassle. Is there a way to leave the script as it is?

在所有这些之前我最初只是想我会用jQuery来添加< script> ; 里面的标签 Template.scriptAppend.rendered 但似乎没有效果,我不明白为什么。

Before all these I initially just think I would use jQuery to add the <script> tags in inside Template.scriptAppend.rendered but there seems to be no effect and I have no idea why.

所以我的问题是,(1)有没有办法让脚本保持原样;(2)什么时候Meteor < head> 还是得到处理?显然$(window).load没有在脚本预期的正确时间执行。

So my questions are, (1) is there a way to leave the script as it is and (2) when is Meteor <head> get processed anyway? Apparently $(window).load is not getting executed at the right time expected by the script.

推荐答案

有时Meteor加载文件与普通Web服务器不同的顺序,这意味着您的功能将不会像您习惯的那样加载。在脑袋中包含外部脚本就可以了,但你应该尝试将所有通常放在 $(document).ready()函数内的所有内容放在<$ c中$ c> Template.templatename.rendered 而不是函数。这对我来说已经成功了。

Sometimes Meteor loads files in a different order than a normal web server, meaning that your functions won't load as you're used to. Including the external script in the head is just fine, but you should try placing everything that would normally go inside the $(document).ready() function inside a Template.templatename.rendered function instead. That has done the trick for me in the past.

这篇关于将外部脚本合并到Meteor中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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