I’m developing a small app designed to embed HTML + JavaScript (JavaScript manages the behavior of HTML) into existing websites. My small app is an ASP.Net MVC 3 app. What’s the best approach for delivering JavaScript to the web client? I do not have access to the web clients except for giving them the URL to retrieve the HTML/JavaScript. The web clients will be retrieving the HTML/JavaScript using jQuery. jQuery will then load the results of the ASP.Net MVC 3 app into the DOM. Should the JavaScript that’s needed to manage the behavior of the embedded HTML simply be a at the end of the HTML fragment? Thanks for your time.
I’m developing a small app designed to embed HTML + JavaScript (JavaScript manages the
Share
If the loading mechanism is in place, and simply inserts the payload of the HTTP request into the DOM somewhere, then including a
<script>as the last tag in the payload is probably the best way to go.Any DOM elements the script depends on should be ready for use when it is executed, and there isn’t anything wrong with that technique that I know of.
You could get more sophisticated, but not without complicating your jQuery loading mechanism.