Library question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric

    Library question

    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="scriptname 1.js"></script>
    <script src="scriptname 2.js"></script>
    <script src="scriptname 3.js"></script>
    <script src="scriptname 4.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

  • kaeli

    #2
    Re: Library question

    In article <DsM_b.382025$I 06.4158687@attb i_s01>, nospam@email.co m
    enlightened us with...[color=blue]
    > 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?[/color]

    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.



    Comment

    • Eric

      #3
      Re: Library question

      kaeli wrote:
      [color=blue]
      > In article <DsM_b.382025$I 06.4158687@attb i_s01>, nospam@email.co m
      > enlightened us with...[color=green]
      >> 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?[/color]
      >
      > Do you have server-side includes or other server-side scripting
      > languages?
      >[/color]
      I have php 4.2.3.
      Eric

      Comment

      • kaeli

        #4
        Re: Library question

        In article <6uN_b.52039$4o .71624@attbi_s5 2>, nospam@email.co m
        enlightened us with...[color=blue]
        > kaeli wrote:
        >[color=green]
        > > In article <DsM_b.382025$I 06.4158687@attb i_s01>, nospam@email.co m
        > > enlightened us with...[color=darkred]
        > >> 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?[/color]
        > >
        > > Do you have server-side includes or other server-side scripting
        > > languages?
        > >[/color]
        > I have php 4.2.3.
        > Eric
        >[/color]

        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.




        --
        --
        ~kaeli~
        A boiled egg in the morning is hard to beat.



        Comment

        • kaeli

          #5
          Re: Library question

          In article <6uN_b.52039$4o .71624@attbi_s5 2>, nospam@email.co m
          enlightened us with...[color=blue]
          > kaeli wrote:
          >[color=green]
          > > In article <DsM_b.382025$I 06.4158687@attb i_s01>, nospam@email.co m
          > > enlightened us with...[color=darkred]
          > >> 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?[/color]
          > >
          > > Do you have server-side includes or other server-side scripting
          > > languages?
          > >[/color]
          > I have php 4.2.3.
          > Eric
          >[/color]

          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.



          Comment

          • Eric

            #6
            Re: Library question - clarification of problem

            Eric wrote:
            [color=blue]
            > 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="scriptname 1.js"></script>
            > <script src="scriptname 2.js"></script>
            > <script src="scriptname 3.js"></script>
            > <script src="scriptname 4.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[/color]

            I think what i want to do is like this:

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

            Then in the file MyJavaScriptRou tines.js
            I would put:
            <script src="scriptname 1.js"></script>
            <script src="scriptname 2.js"></script>
            <script src="scriptname 3.js"></script>
            <script src="scriptname 4.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

            Comment

            • Michael Winter

              #7
              Re: Library question - clarification of problem

              On Tue, 24 Feb 2004 19:54:49 GMT, Eric <nospam@email.c om> wrote:

              [snip]
              [color=blue]
              > I think what i want to do is like this:
              >
              > In my html page i would put this:
              > <script src="MyJavaScri ptRoutines.js"> </script>
              >
              > Then in the file MyJavaScriptRou tines.js
              > I would put:
              > <script src="scriptname 1.js"></script>
              > <script src="scriptname 2.js"></script>
              > <script src="scriptname 3.js"></script>
              > <script src="scriptname 4.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).[/color]

              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:

              [MyJavaScriptRou tines.js]
              document.write(
              '<script type="text/javascript" src="scriptname 1.js"><\/script>');
              document.write(
              '<script type="text/javascript" src="scriptname 2.js"><\/script>');
              document.write(
              '<script type="text/javascript" src="scriptname 3.js"><\/script>');
              document.write(
              '<script type="text/javascript" src="scriptname 4.js"><\/script>');

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

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

              http://groups.google.c om/groups?q=group% 3Acomp.lang.jav ascript+include &ie=UTF-8&oe=UTF-8&hl=en&btnG=Go ogle+Search

              Mike

              --
              Michael Winter
              M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

              Comment

              • Eric

                #8
                Re: Library question - clarification of problem

                Michael Winter wrote:
                [color=blue]
                > On Tue, 24 Feb 2004 19:54:49 GMT, Eric <nospam@email.c om> wrote:
                >
                > [snip]
                >[color=green]
                >> I think what i want to do is like this:
                >>
                >> In my html page i would put this:
                >> <script src="MyJavaScri ptRoutines.js"> </script>
                >>
                >> Then in the file MyJavaScriptRou tines.js
                >> I would put:
                >> <script src="scriptname 1.js"></script>
                >> <script src="scriptname 2.js"></script>
                >> <script src="scriptname 3.js"></script>
                >> <script src="scriptname 4.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).[/color]
                >
                > 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:
                >
                > [MyJavaScriptRou tines.js]
                > document.write(
                > '<script type="text/javascript" src="scriptname 1.js"><\/script>');
                > document.write(
                > '<script type="text/javascript" src="scriptname 2.js"><\/script>');
                > document.write(
                > '<script type="text/javascript" src="scriptname 3.js"><\/script>');
                > document.write(
                > '<script type="text/javascript" src="scriptname 4.js"><\/script>');
                >
                > [HTML document]
                > <script type="text/javascript"
                > src="MyJavaScri ptRoutines.js"> </script>
                >
                > This issue has been covered a number of times in the past (watch for
                > wrap):
                >
                >[/color]
                http://groups.google.c om/groups?q=group% 3Acomp.lang.jav ascript+include &ie=UTF-8&oe=UTF-8&hl=en&btnG=Go ogle+Search[color=blue]
                >
                > Mike
                >[/color]

                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

                Comment

                • Brian Genisio

                  #9
                  Re: Library question - clarification of problem

                  Eric wrote:
                  [color=blue]
                  >
                  > 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.
                  >[/color]

                  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.
                  [color=blue]
                  > 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?
                  >[/color]
                  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

                  Comment

                  Working...