This question already has an answer here:
In PhP you can.
In html, you sort of can with <script src="...">
tag
but what about if we have a .js file and we want to include another .js file. How would we do so?
This question already has an answer here:
In PhP you can.
In html, you sort of can with <script src="...">
tag
but what about if we have a .js file and we want to include another .js file. How would we do so?
If you mean in a browser context, not directly, but you can use a loader like at RequireJS (there are several).
Or to do it manually:
Note, though,that with the above the functions and such in the other file won't be available for use right away. The code above starts the process of loading the file, but it continues asynchronously. You can use events to know that the load is complete (primarily the
load
event, but on older versions of IE you have to useonreadystatechange
-- this is one reason people use loaders!).