Library question

E

Eric

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
 
K

kaeli

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
 
K

kaeli

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.

--
 
E

Eric

Eric said:
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
 
M

Michael Winter

[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=g...de&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search

Mike
 
E

Eric

Michael said:
[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=g...de&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
 
B

Brian Genisio

Eric said:
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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top