Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does an external .js file require <script> tags?

Tags:

Does an external .js file require internal and containing tags to work?

like image 922
TroubledGuym Avatar asked Oct 04 '10 23:10

TroubledGuym


People also ask

What is more appropriate way to include JavaScript as an external file?

Learn HTML After creating, add it to the HTML file in the script tag. The src attribute is used to include that external JavaScript file. If you have more than one external JavaScript file, then add it in the same web page to increase performance of the page.

What tag in JavaScript contains either scripting statements or external js file?

The <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute.

What is an external JavaScript file?

It provides code re usability because single JavaScript file can be used in several html pages. An external JavaScript file must be saved by . js extension. It is recommended to embed all JavaScript files into a single file. It increases the speed of the webpage.


2 Answers

No, they're not needed, in fact you'll get a syntax error if you include them.

Your .js files should contain only JavaScript, no HTML tags around it, like would have inside a page.

like image 81
Nick Craver Avatar answered Oct 21 '22 11:10

Nick Craver


No, it does not. The external file just needs the code.
Then you just need to do <script src="file.js" type="text/javascript"></script>.

like image 36
Rocket Hazmat Avatar answered Oct 21 '22 11:10

Rocket Hazmat