0

When I examine HTMl5- Bootstrap templates, I see that, Jquery and the other javascript plugins are added at the bottom of the page. There is no problem, template works regulary.

But when I try to add some third party javascript plugin (forexample Floating-WhatsApp-Message-Button), surprise! It doesnt work even it based on Jquery.

So I try many and many things. But mostly this solve my problem: Moving Jquery.js calling tag inside to head tag.

I can't understand that. What is my sin? Is it a normal solution? Then why jquery.js tag is at the bottom of page in regular templates?

mustklc
  • 11
  • 1
  • 2
    As long as your *plugin* `script src=` is *after* the jquery `script src=`, it doesn't (for functionality) matter where it is. As long as you don't have any ` – freedomn-m Sep 06 '21 at 15:23
  • 2
    Because scripts tags are read and parsed in order. Putting scripts that depend on scripts that aren't loaded yet fail. You're asking for bicycles before wheels have been invented. – zero298 Sep 06 '21 at 15:24
  • There's plenty of answers/discussions regarding putting scripts in head vs at the end of body (on SO and off). In summary: put in the head so that it's ready for your page / put at the end so it doesn't hold up rendering of your page while it parses the js. Modern browsers cache *parsed* js, so if you're using a CDN or multiple pages, it will only be a "hit" on the first load. – freedomn-m Sep 06 '21 at 15:29
  • Does this answer your question? [Where to place JavaScript in an HTML file?](https://stackoverflow.com/questions/196702/where-to-place-javascript-in-an-html-file) (and numerous linked answers from that one) – freedomn-m Sep 06 '21 at 15:31
  • @freedomn-m I dont think this question is about whether to put at bottom or top of body/head. I think it misunderstanding dependency load order. – zero298 Sep 06 '21 at 15:32
  • 1
    @zero298 I completely agree with you (upvoted your comment) but didn't want to reiterate what you said. I went with the "why is jquery tag at the bottom [normally]?" part of the question which is pretty much the only actual question, despite it not being what's really asked - in order to find a question to vote-close it against :) (otherwise it'll probably just get left) – freedomn-m Sep 06 '21 at 15:35

0 Answers0