Library question

Discussion in 'Javascript' started by Eric, Feb 24, 2004.

  1. Eric

    Eric Guest

    I want to have one statement in my web page that includes a single file (for
    example "Mylib.inc" that contains a list of ".js" files to include.
    Is that possible? And if so can some one show me the basic format to use?

    This would allow me to add and remove scripts from my pages without having
    to edit each page, only w3ouyld need to make a change in the MyLib.inc file

    I'm envisioning MyLib.inc to look something like this:

    <script src="scriptname1.js"></script>
    <script src="scriptname2.js"></script>
    <script src="scriptname3.js"></script>
    <script src="scriptname4.js"></script>

    Another thought: Can .css files also be put in there? (probably not huh.) so
    i could include everything with one include in my web page?
    Thanks
    Eric
    Eric, Feb 24, 2004
    #1
    1. Advertising

  2. Eric

    kaeli Guest

    In article <DsM_b.382025$I06.4158687@attbi_s01>,
    enlightened us with...
    > I want to have one statement in my web page that includes a single file (for
    > example "Mylib.inc" that contains a list of ".js" files to include.
    > Is that possible?


    Do you have server-side includes or other server-side scripting
    languages?

    --
    --
    ~kaeli~
    Punctuation, capitalization, and grammar are your friends,
    and will help people think that you aren't such an ignorant
    moron, after all.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    kaeli, Feb 24, 2004
    #2
    1. Advertising

  3. Eric

    Eric Guest

    kaeli wrote:

    > In article <DsM_b.382025$I06.4158687@attbi_s01>,
    > enlightened us with...
    >> I want to have one statement in my web page that includes a single file
    >> (for example "Mylib.inc" that contains a list of ".js" files to include.
    >> Is that possible?

    >
    > Do you have server-side includes or other server-side scripting
    > languages?
    >

    I have php 4.2.3.
    Eric
    Eric, Feb 24, 2004
    #3
  4. Eric

    kaeli Guest

    In article <6uN_b.52039$4o.71624@attbi_s52>,
    enlightened us with...
    > kaeli wrote:
    >
    > > In article <DsM_b.382025$I06.4158687@attbi_s01>,
    > > enlightened us with...
    > >> I want to have one statement in my web page that includes a single file
    > >> (for example "Mylib.inc" that contains a list of ".js" files to include.
    > >> Is that possible?

    > >
    > > Do you have server-side includes or other server-side scripting
    > > languages?
    > >

    > I have php 4.2.3.
    > Eric
    >


    I'd make all my pages .php, then, and use include to include a small
    header file with all the script and css you might like in it.

    http://www.php-include.com/


    --
    --
    ~kaeli~
    A boiled egg in the morning is hard to beat.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    kaeli, Feb 24, 2004
    #4
  5. Eric

    kaeli Guest

    In article <6uN_b.52039$4o.71624@attbi_s52>,
    enlightened us with...
    > kaeli wrote:
    >
    > > In article <DsM_b.382025$I06.4158687@attbi_s01>,
    > > enlightened us with...
    > >> I want to have one statement in my web page that includes a single file
    > >> (for example "Mylib.inc" that contains a list of ".js" files to include.
    > >> Is that possible?

    > >
    > > Do you have server-side includes or other server-side scripting
    > > languages?
    > >

    > I have php 4.2.3.
    > Eric
    >


    I forgot to add:
    If you have control of the server, you can make it think html files are
    php and have them parsed. No need to change extension on all your files.

    --
    --
    ~kaeli~
    A boiled egg in the morning is hard to beat.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    kaeli, Feb 24, 2004
    #5
  6. Eric

    Eric Guest

    Re: Library question - clarification of problem

    Eric wrote:

    > I want to have one statement in my web page that includes a single file
    > (for example "Mylib.inc" that contains a list of ".js" files to include.
    > Is that possible? And if so can some one show me the basic format to use?
    >
    > This would allow me to add and remove scripts from my pages without having
    > to edit each page, only w3ouyld need to make a change in the MyLib.inc
    > file
    >
    > I'm envisioning MyLib.inc to look something like this:
    >
    > <script src="scriptname1.js"></script>
    > <script src="scriptname2.js"></script>
    > <script src="scriptname3.js"></script>
    > <script src="scriptname4.js"></script>
    >
    > Another thought: Can .css files also be put in there? (probably not huh.)
    > so i could include everything with one include in my web page?
    > Thanks
    > Eric


    I think what i want to do is like this:

    In my html page i would put this:
    <script src="MyJavaScriptRoutines.js"></script>

    Then in the file MyJavaScriptRoutines.js
    I would put:
    <script src="scriptname1.js"></script>
    <script src="scriptname2.js"></script>
    <script src="scriptname3.js"></script>
    <script src="scriptname4.js"></script>

    With the end result that scriptname 1 2 3 and 4 are included in the html
    page.

    But that doesnt seem to work. So what this all boils down to is how do you
    do a nested .js include. Where one .js file includes another (or two or
    three) .js file(s).
    I hope this clears up my question some.
    Thanks
    Eric
    Eric, Feb 24, 2004
    #6
  7. Re: Library question - clarification of problem

    On Tue, 24 Feb 2004 19:54:49 GMT, Eric <> wrote:

    [snip]

    > I think what i want to do is like this:
    >
    > In my html page i would put this:
    > <script src="MyJavaScriptRoutines.js"></script>
    >
    > Then in the file MyJavaScriptRoutines.js
    > I would put:
    > <script src="scriptname1.js"></script>
    > <script src="scriptname2.js"></script>
    > <script src="scriptname3.js"></script>
    > <script src="scriptname4.js"></script>
    >
    > With the end result that scriptname 1 2 3 and 4 are included in the html
    > page.
    >
    > But that doesnt seem to work. So what this all boils down to is how do
    > you do a nested .js include. Where one .js file includes another (or two
    > or three) .js file(s).


    There is no native way to include files. That is, there is no construct
    similar to the C/C++ #include preprocessor directive, or Java's import
    declaration.

    The best you can manage with JavaScript is using document.write() calls to
    write the SCRIPT elements. However, some browsers don't cope with this too
    well. The route that Kaeli is trying to take you down is the most
    reliable, and therefore the most recommended, though I do realise that in
    the context of a library, a server-side solution might not be very
    practical in the general case.

    The document.write() approach would look like:

    [MyJavaScriptRoutines.js]
    document.write(
    '<script type="text/javascript" src="scriptname1.js"><\/script>');
    document.write(
    '<script type="text/javascript" src="scriptname2.js"><\/script>');
    document.write(
    '<script type="text/javascript" src="scriptname3.js"><\/script>');
    document.write(
    '<script type="text/javascript" src="scriptname4.js"><\/script>');

    [HTML document]
    <script type="text/javascript"
    src="MyJavaScriptRoutines.js"></script>

    This issue has been covered a number of times in the past (watch for wrap):

    http://groups.google.com/groups?q=group%3Acomp.lang.javascript+include&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search

    Mike

    --
    Michael Winter
    (replace ".invalid" with ".uk" to reply)
    Michael Winter, Feb 24, 2004
    #7
  8. Eric

    Eric Guest

    Re: Library question - clarification of problem

    Michael Winter wrote:

    > On Tue, 24 Feb 2004 19:54:49 GMT, Eric <> wrote:
    >
    > [snip]
    >
    >> I think what i want to do is like this:
    >>
    >> In my html page i would put this:
    >> <script src="MyJavaScriptRoutines.js"></script>
    >>
    >> Then in the file MyJavaScriptRoutines.js
    >> I would put:
    >> <script src="scriptname1.js"></script>
    >> <script src="scriptname2.js"></script>
    >> <script src="scriptname3.js"></script>
    >> <script src="scriptname4.js"></script>
    >>
    >> With the end result that scriptname 1 2 3 and 4 are included in the html
    >> page.
    >>
    >> But that doesnt seem to work. So what this all boils down to is how do
    >> you do a nested .js include. Where one .js file includes another (or two
    >> or three) .js file(s).

    >
    > There is no native way to include files. That is, there is no construct
    > similar to the C/C++ #include preprocessor directive, or Java's import
    > declaration.
    >
    > The best you can manage with JavaScript is using document.write() calls to
    > write the SCRIPT elements. However, some browsers don't cope with this too
    > well. The route that Kaeli is trying to take you down is the most
    > reliable, and therefore the most recommended, though I do realise that in
    > the context of a library, a server-side solution might not be very
    > practical in the general case.
    >
    > The document.write() approach would look like:
    >
    > [MyJavaScriptRoutines.js]
    > document.write(
    > '<script type="text/javascript" src="scriptname1.js"><\/script>');
    > document.write(
    > '<script type="text/javascript" src="scriptname2.js"><\/script>');
    > document.write(
    > '<script type="text/javascript" src="scriptname3.js"><\/script>');
    > document.write(
    > '<script type="text/javascript" src="scriptname4.js"><\/script>');
    >
    > [HTML document]
    > <script type="text/javascript"
    > src="MyJavaScriptRoutines.js"></script>
    >
    > This issue has been covered a number of times in the past (watch for
    > wrap):
    >
    >

    http://groups.google.com/groups?q=group%3Acomp.lang.javascript+include&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search
    >
    > Mike
    >


    OK, i'll ponder both solutions, (thanks to both of you).
    I think I'd rather not go the php renaming route at this time tho, Thats a
    big change in my site and I've got a lot of pages. No matter what i do i'll
    have to change all my pages but I am hoping to find a solution that is
    flexible and makes it so i dont have to do this again.

    Maybe a full java implementation would be the way to go? You mentioned java
    import directive. I've not done any java at all, what does it take to get
    into it? Is it worth the effort?

    I've got a css in all my pages now, too bad i couldnt stick the script
    directives in there.

    Thanks
    Eric
    Eric, Feb 24, 2004
    #8
  9. Re: Library question - clarification of problem

    Eric wrote:

    >
    > OK, i'll ponder both solutions, (thanks to both of you).
    > I think I'd rather not go the php renaming route at this time tho, Thats a
    > big change in my site and I've got a lot of pages. No matter what i do i'll
    > have to change all my pages but I am hoping to find a solution that is
    > flexible and makes it so i dont have to do this again.
    >


    Remember what kaeli said... if you have access to configure the server,
    there is a very simple config file (php.conf, I think?) option that you
    can change to tell your server to do a PHP parse on .html files. It
    works like a charm... but it is a small overhead extra on the server's
    side, since it parses PHP for ever html file. I used it on a
    low-traffic site with 0 impact.

    > Maybe a full java implementation would be the way to go? You mentioned java
    > import directive. I've not done any java at all, what does it take to get
    > into it? Is it worth the effort?
    >

    No, not at all. Java is not for creating HTML pages... (well, I
    suppose, you can do it as a server-side app, but that is not what we are
    talking about, since it would also require suffix changing) The Java
    example was to point out that other programming languages support
    include, but HTML does not. Java is a programming language...
    Javascript is a scripting language, and HTML is a markup language.
    Stick to HTML.

    Brian
    Brian Genisio, Feb 25, 2004
    #9
    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. Mythran
    Replies:
    0
    Views:
    2,420
    Mythran
    Aug 24, 2004
  2. Alan Ferrandiz [MCT]
    Replies:
    0
    Views:
    445
    Alan Ferrandiz [MCT]
    Sep 11, 2004
  3. Sweep

    Library in library...

    Sweep, Dec 8, 2003, in forum: C++
    Replies:
    1
    Views:
    383
    Jack Klein
    Dec 9, 2003
  4. Replies:
    6
    Views:
    830
    red floyd
    May 10, 2005
  5. iceColdFire

    Static library Vs. Dynamic library

    iceColdFire, May 17, 2005, in forum: C++
    Replies:
    3
    Views:
    17,043
Loading...

Share This Page