Disadvantage of including JavaScript files within a JavaScript file?

V

vunet

What's the possible disadvantage of including JavaScript files within
a JavaScript file? Why I needed it? For the sake of easy management,
perhaps? Any load speed disadvantage? Example below:

document.write('<script type="text/javascript" src="'+libraryName+'"><
\/script>');
 
T

Thomas 'PointedEars' Lahn

vunet said:
What's the possible disadvantage of including JavaScript files within
a JavaScript file?
Unreliability.

Why I needed it? For the sake of easy management, perhaps?

I do not need it. I do not know know why you did.
Any load speed disadvantage?

There is no load speed advantage in this to begin with: Provided that it
works, a script needs to be loaded, compiled and interpreted in order to
load another script.
Example below:

document.write('<script type="text/javascript" src="'+libraryName+'"><
\/script>');

You do not need to escape ETAGO's within external script resources as they
are not parsed by a markup parser (however, escaping them always can ease
maintenance).

You might want to escape `libraryName'. Anyway, you cannot be sure if and
where this `script' element is inserted if the statement is in an external
script resource.

With internal scripts, you simply put the script element where it belongs
(before the `script' element that includes code that uses features defined
in the former) and forget about the document.write() nonsense.


PointedEars
 
L

Laser Lips

There is one possible disadvantage with including files externally
concerning debugging. This only really concerns Internet explorer.

If you have an error in one of your scripts, you'll get a line number,
but the number will not correspond to the correct line unless all the
JS code is inline with the HTML.

To explain this, if you have the following code...

<html>
<head>
<script src='somescript.js'></script>
</head>
<body>
....HTML
</body>
</html>

and somescript.js looks like

-----------
alert("ok");
allertt("not ok");
-----------

You would normall get an error on line 2, but as the script is
included on line 3, the error message will tell you its on line 5, and
when multiple scripts are included it can be a nightmare to find the
line.

-------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top