This warning will continue until you inject the script into the body of the document.
I would recommend using $.getScript
, as this will load the script correctly. I do not understand why you want all javascripts to be on the same page from the first place. You probably want them in a separate file anyway to facilitate maintenance on the road and separate problems.
You can also use javascript vanilla for this:
var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.setAttribute('src','your_script.js'); head.appendChild(script);
If you insist on doing it this way, try typing it directly into the head
document, not the body
, and see if that helps.
In a more general note - it looks like you are creating a one-page application (SPA) - did you study JS frameworks like Angular
, Backbone
, etc.? they will handle all the heavy lifting for you and help you scale your application better. It smells a bit like trying to reinvent the wheel and can be a great thing as an educational process, but it may not be such a good idea in the long run.
Hope this helps.
source share