Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.3][bug] Scripts (also in production) will be loaded at the top of body tag instead of head #6672

Closed
TimoRuetten opened this issue Apr 1, 2016 · 9 comments

Comments

@TimoRuetten
Copy link

image

It seems that the new Meteor Version will load all scripts - also minified in production - at the top of the body tag. Because of this its difficult for me to add custom script tags in my head.html file because these scripts have to be loaded AFTER the meteor scripts are loaded.

< Meteor 1.3 this works fine.

My Situation is:

I need to add a Script inside the head tag (or where ever) from a extern CDN. But: This Script needs jQuery which is loaded in the body - so after my script was added. When I take a look at this file https://github.com/zol/meteor/blob/74055f410df7b12d49b343f943c4c37f21cad965/packages/boilerplate-generator/boilerplate_web.browser.html it seems that its impossible to load scripts AFTER Meteor generated the JS files. So in this situation I have to make a package out of every single script I need to be loaded after meteor generated the files.

Is there no other solution ?

@TimoRuetten TimoRuetten changed the title Scripts (also in production) will be loaded at the top of body tag instead of head [1.3][bug] Scripts (also in production) will be loaded at the top of body tag instead of head Apr 1, 2016
@abernix
Copy link
Contributor

abernix commented Apr 1, 2016

This is (by design) because of #6375 in order to aid with SSR support. There is some new dynamicHead support that might be what you're looking for (though I'm not sure how exactly it works). Maybe check #3860 for some details of how to do what you need – it seems like it is possible.

@TimoRuetten
Copy link
Author

Thanks @abernix - currently I am also not sure how the dynamicHead works but I will try to figure out. Currently its not implemented in the docs of meteor. I will close this issue - thanks.

@TimoRuetten
Copy link
Author

I have to reopen it - because the dynamicHead is not doing what I need. The dynamicHead is still what I am using and its loaded to the head - but the generated scripts by meteor are not added to head anymore. So what I need is more something like a dynamicFooter so I can add scripts AFTER the meteor generated scripts.

@TimoRuetten TimoRuetten reopened this Apr 1, 2016
@Primigenus
Copy link
Contributor

What happens if you use <script defer>?

What happens if you wait until Meteor.startup to load the script using $.getScript or something similar?

@abernix
Copy link
Contributor

abernix commented Apr 1, 2016

Or just put a file that loads whatever you want into your client JavaScript?

$.getScript("http://my_lovely_script.js");

Unsure of the exact issue, so not sure what to offer.

@TimoRuetten
Copy link
Author

@abernix & @Primigenus thats absolutly true. Now we will do this by adding the script in our JS files after everything else got loaded. Its just sad that its not possible anymore by doing this with HTML like before - but thats okay. Have to change a few things and everything will work like before.

@abernix
Copy link
Contributor

abernix commented Apr 1, 2016

Don't be too sad. The benefits from this change should be far outweigh the pain once they're all built out. 😺

@strikeout
Copy link

For my dev-environment I modified the boilerplate-generator so all scripts are not appended into <body> directly but into a <div id="meteorScripts">..</div>.

Advantage is the browser does not slow down when reloading with open dev-tools (less nodes to render).
Also it makes debugging DOM structure much easier as there is less clutter.

Any reason why we not implement this officially? Is there any disadvantage to placing script tags inside a div?

@hwillson
Copy link
Contributor

@strikeout See meteor/meteor-feature-requests#24. The changes proposed in that feature request would allow you to place the scripts anywhere (using a tag like <meteor-bundled-js/>). That FR is pull-requests-encouraged if you're interested in helping out - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants