omar199 Posted May 10, 2006 Share Posted May 10, 2006 I have one HTML page that is requiring a JS file with a lot of code in it. I was thinking about splitting up a part of that JS file into another JS file. Does anyone know if there is a way for the first JS file (called by the HTML file) can "require" or "include" the new JS file as well?(I'm trying to do this without modifying the HTML) Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 10, 2006 Share Posted May 10, 2006 Most likely it can, but if I may, I would suggest just including both files in the html Link to comment Share on other sites More sharing options...
scott100 Posted May 10, 2006 Share Posted May 10, 2006 Does anyone know if there is a way for the first JS file (called by the HTML file) can "require" or "include" the new JS file as well?<{POST_SNAPBACK}> Put this in your first JS file, where x.js is the other included filedocument.write('<script src="x.js"></script>'); Link to comment Share on other sites More sharing options...
Webworldx Posted May 10, 2006 Share Posted May 10, 2006 <\/script> Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 10, 2006 Share Posted May 10, 2006 But thee point is, wouldn't that slow down the loading time? because when you load both at the html document, they get loaded simultaniously Elseway, wel, not simultaniously Link to comment Share on other sites More sharing options...
Jonas Posted May 10, 2006 Share Posted May 10, 2006 You could use a serverside script, like php:script1.php:document.write("Hello");<?php include "script2.js" ?>document.write("World!");That way the script2.js file would be loaded on the server into the script1.php file, and you could still call the file in html as a text/javascript file I think. Link to comment Share on other sites More sharing options...
omar199 Posted May 12, 2006 Author Share Posted May 12, 2006 Thanks for all the help everyone.I think that I will take the first method that Dan suggested, simply modifying the HTML files. I'll just use homesite or dreamweaver to run a global find and replace to change the <script src=file1></script> to include both (change that to <script src=file1></script><script src=file2></script> Link to comment Share on other sites More sharing options...
Chocolate570 Posted May 14, 2006 Share Posted May 14, 2006 But thee point is, wouldn't that slow down the loading time? because when you load both at the html document, they get loaded simultaniously wink.gif Elseway, wel, not simultaniously tongue.gifIf you have a server or a connection so slow that you can actually tell a difference between the loading times of those, then you should shoot yourself anyway, and the problem is immediatley solved. Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 15, 2006 Share Posted May 15, 2006 Small scripts don't slow the rate, but when you add more, they do Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now