Inclusion of external script in Meteor

I include an external theme in Meteor. It has some scripts loaded to the end of the body tag. The tag <script>does not work if inside <body>the Meteor template.

The topic uses js such as Bootstrap, jquery and other other, possibly external JS libraries (which are also placed at the end, before </body>. The last script is a custom.jsscript that is thematic. Inside the script there are two anonymous functions besides regular function statements , two ifblocks at the top level, callback $(document).readyand callback $(window).load.

What is the best way to load scripts with the lowest temperature? I tried moving all the scripts inside <head>the Meteor template. But some effects are missing. I think it may $(window).loadnot be called at the right time. So I call it inside Template.scriptAppend.rendered, where scriptAppend is the template for partial right to the end </body>. I also move two anonymous functions and two blocks ifinside $(window).load. It works, but it’s such a hassle. Is there any way to leave the script as is?

First of all, I initially just think that I will use jQuery to add tags <script>inside Template.scriptAppend.rendered, but there seems to be no effect, and I have no idea why.

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

+3
source share
1 answer

Sometimes Meteor uploads files in a different order than a regular web server, which means that your functions will not load as you used to. Inclusion of an external script in the head is just fine, but you should try to place everything that usually comes inside a function $(document).ready()inside a function Template.templatename.rendered. This has done the trick for me in the past.

+1
source

Source: https://habr.com/ru/post/1534275/


All Articles