Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Disadvantage of including JavaScript files within a JavaScript file? (http://www.velocityreviews.com/forums/t936450-disadvantage-of-including-javascript-files-within-a-javascript-file.html)

vunet 07-07-2008 04:51 PM

Disadvantage of including JavaScript files within a JavaScript file?
 
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>');

Thomas 'PointedEars' Lahn 07-07-2008 05:32 PM

Re: Disadvantage of including JavaScript files within a JavaScriptfile?
 
vunet wrote:
> 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
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>

Laser Lips 07-08-2008 03:18 PM

Re: Disadvantage of including JavaScript files within a JavaScriptfile?
 
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.

-------


All times are GMT. The time now is 10:25 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.