Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a reference to a .js file in a javascript file?

What is the correct syntax for adding an external reference to a JavaScript file (.js) within another JavaScript file?

like image 983
Michael Kniskern Avatar asked Mar 04 '26 07:03

Michael Kniskern


2 Answers

There isn't any.

You can add a <script> block to the document, but it will execute asynchronously.

like image 148
SLaks Avatar answered Mar 05 '26 20:03

SLaks


Alternatively store all your .js files in a php file.

<script src="js.php" type="text/javascript"></script>

php:

<?php
require 'js/myjs1.js';
require 'js/myjs2.js';
?>
like image 41
woodscreative Avatar answered Mar 05 '26 20:03

woodscreative



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!