javascript file include other javascripts links?

Can a javascript file include links to other javascript files?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sjklein42Commented:
One good technique that works by generating a script tag dynamically::

http://www.cryer.co.uk/resources/javascript/script17_include_js_from_js.htm
leakim971PluritechnicianCommented:
simple js :

var script = document.createElement("script");
script.src = "/path/to/other/javascript/somejavascript.js";
document.head.appendChild(script);

jQuery : http://api.jquery.com/jQuery.getScript/

$.getScript("/path/to/other/javascript/somejavascript.js");

Tom KnowltonWeb developerAuthor Commented:
Why are these solutions so convoluted?

Can't I just do this:

------------------------------------------
top of file named somejavascript.js
------------------------------------------

<script src="../../Scripts/anotherscript.js" type="text/javascript"></script><script <src="../../Scripts/andyetanotherscript.js" type="text/javascript"></script>

function()
{

}

----------------------------------------------
bottom of flie named somejavascript.js
----------------------------------------------



Then in some html page somewhere we do:

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



Would this work?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

leakim971PluritechnicianCommented:
no you can't
Tom KnowltonWeb developerAuthor Commented:
Let say I have the following in my HTML <head> section:


<script type="text/javascript">

    $(document).ready(function ()
    {
        $('select').change(function ()
        {
            $('#waitanimationtext').text(" Retrieving Data - Please wait...");
            $('option').throbber({ parent: "#waitanimation", image: "ajax-loader.gif" });
        });
    });
    
</script>

Open in new window

\

Can I take everything that is between the <script></script> tags and move it to an external file called textbookthrobber.js  (for example)

and then just inlclude textbookthrobber.js like this?

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


and would it work as long as I had the following declarations ABOVE that include:

<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.throbber.js" type="text/javascript"></script>

leakim971PluritechnicianCommented:
yes of course but please not textbookthrobber.js don't contains script tag, it contains only the javascript code

and you need to place <script src="../../Scripts/textbookthrobber.js" type="text/javascript"></script> after the jQuery plugin because it use jQuery
Tom KnowltonWeb developerAuthor Commented:
Assuming that this would work, could I create a bunch of external files for use with jquery...like ths?

external file nameavailthrobber.js
 $(document).ready(function ()
    {
  $('input[id*="ButtonCheckAvail"]').mousedown(function ()
        {
            $('#waitanimationtext').text(" Checking Name Availability - Please wait...");
            $(this).throbber({ parent: "#waitanimation", image: "ajax-loader.gif" });
        });
  });

Open in new window


external file passwordcheckthrobber.js
 $(document).ready(function ()
    {
  $('input[id*="ButtonChangePW"]').mousedown(function ()
        {
            $('#waitanimationtext').text(" Changing Password - Please wait...");
            $(this).throbber({ parent: "#waitanimation", image: "ajax-loader.gif" });
        });
  });

Open in new window




Then back in the main HTML page I would go:

<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.throbber.js" type="text/javascript"></script>
<script src="../../Scripts/nameavailthrobber.js" type="text/javascript"></script>
<script src="../../Scripts/passwordcheckthrobber.js" type="text/javascript"></script>
leakim971PluritechnicianCommented:
try it first inside your page, if it work fine, move it to an external file without any modification, it will work
again, the external file don't contains the script tags

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
thx
leakim971PluritechnicianCommented:
don't forget to respect order

the dependencies first
Tom KnowltonWeb developerAuthor Commented:
>>>>don't forget to respect order

the dependencies first

==================================

Understood.

So far it is working just great.....helps to organize it some....some of the js is for specific clients, so it is nice to be able to break it up like this.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.