Reputation: 43
What problems can be caused by placing comments in a script tag calling an external script? My coworker told me this is not a good practice.
Something like this:
<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript">
// import jQuery
// cdn refers to a remotely hosted library
</script>
Upvotes: 4
Views: 174
Reputation: 5751
Maybe your coworker is concerned you'll get in the habit of doing this
<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript">
// import jQuery
// cdn refers to a remotely hosted library
</script>
And then eventually struggle to figure out why this doesn't work
<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript">
$(document).ready(function() {
$('#ActionButton').click(DoAction);
});
</script>
Because you've developed a bad habit
Upvotes: 1
Reputation: 816312
No problems at all. If the script
element has a src
attribute, the content is ignored.
Maybe your coworker was referring to HTML comments inside the script tag, which where used for ancient browsers which did not support JavaScript?
<script>
<!--
// JS was here
// -->
</script>
Are HTML comments inside script tags a best practice?
Upvotes: 3
Reputation: 13786
Nothing wrong, maybe readability. The content will also be overwritten by the source.
<!-- import jQuery. CDN refers to a remotely hosted library -->
<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript"></script>
Upvotes: 3