Disadvantage of including JavaScript files within a JavaScript file?

Discussion in 'Javascript' started by vunet, Jul 7, 2008.

  1. vunet

    vunet Guest

    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>');
     
    vunet, Jul 7, 2008
    #1
    1. Advertising

  2. 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$>
     
    Thomas 'PointedEars' Lahn, Jul 7, 2008
    #2
    1. Advertising

  3. vunet

    Laser Lips Guest

    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.

    -------
     
    Laser Lips, Jul 8, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe
    Replies:
    3
    Views:
    4,484
    Sudsy
    Dec 5, 2003
  2. dorayme
    Replies:
    11
    Views:
    1,095
    Neredbojias
    Sep 21, 2005
  3. PenguinPig

    Disadvantage of Resource

    PenguinPig, Jun 24, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    372
    PenguinPig
    Jun 24, 2006
  4. Dipankar
    Replies:
    17
    Views:
    10,768
    Arne Vajhøj
    Aug 1, 2009
  5. Method Man

    Disadvantage of using 'inline'

    Method Man, Sep 24, 2004, in forum: C Programming
    Replies:
    18
    Views:
    625
    CBFalconer
    Sep 30, 2004
Loading...

Share This Page