473,774 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create references to external scipt files from within an external script file

Just discovered this technique. Is this old hat? Would there be any
disadvantage to doing this?

In your external .js file:

/*
Summary: includes external scripts in this external script
so that you don't have to reference them within the (x)html
document
files.
Remarks:
In effect this inserts something like
<script type="text/javascript"
src="referencin gExternalLibrar iesB.js"></script>
into the html document.
Param:
scriptUrl (String)
an absolute or relative url.
Usage: In your external scripts, at the top of your documents,
include("file:///C:/temp/myScript.js");
include("otherS cript");
*/
function include(scriptS rc) {
var headElement = document.getEle mentsByTagName( "head")[0];
var scriptElement = document.create Element("script ");
scriptElement.s etAttribute("ty pe", "text/javascript");
scriptElement.s etAttribute("sr c", scriptSrc);
headElement.app endChild(script Element);
}

Full example online:
<http://www.softmake.com.au/webScript...alLibraries.ht
ml>
Nov 4 '05 #1
6 1701
Mellow Crow wrote:
Just discovered this technique. Is this old hat?
It is not old hat as such because the number of browsers that fully
support the technique only recently increased to the point where it
could be considered viable in an Internet context. It has been known,
and experimented with, for some considerable time.
Would there be any
disadvantage to doing this?

<snip>

Yes, you will be excluding some browsers from being able to use the
script without necessarily having a good reason for doing so.

Richard.
Nov 4 '05 #2
Richard, both of your points are helpful, thanks.

Richard Cornford wrote:
Mellow Crow wrote:
Just discovered this technique. Is this old hat?


It is not old hat as such because the number of browsers that fully
support the technique only recently increased to the point where it
could be considered viable in an Internet context. It has been known,
and experimented with, for some considerable time.


Yes. It's a W3C/standards/"modern" technique so it's new in that sense.
Would there be any
disadvantage to doing this?

<snip>

Yes, you will be excluding some browsers from being able to use the
script without necessarily having a good reason for doing so.


Yes. That's true. Raises the fundamental issue of whether you should design
for graceful degradation or simply ignore older browsers. I'm sure this has
been thrashed out elsewhere.

May have found a second potential disadvantage.
When testing your page from served local web server (not file system) AND
you use the technique of this thread AND
you are referencing a script file from outside the root of your domain,
using the file system (eg file:///C:/Data/...)
THEN
You get errors :(

Nov 4 '05 #3
Mellow Crow wrote:
May have found a second potential disadvantage.
When testing your page from served local web server (not file system) AND
you use the technique of this thread AND
you are referencing a script file from outside the root of your domain,
using the file system (eg file:///C:/Data/...)
THEN
You get errors :(


Works as designed.
PointedEars
Nov 4 '05 #4
Mellow Crow said the following on 11/4/2005 6:27 AM:
Richard, both of your points are helpful, thanks.

Richard Cornford wrote:
Mellow Crow wrote:
Just discovered this technique. Is this old hat?


It is not old hat as such because the number of browsers that fully
support the technique only recently increased to the point where it
could be considered viable in an Internet context. It has been known,
and experimented with, for some considerable time.

Yes. It's a W3C/standards/"modern" technique so it's new in that sense.

Would there be any
disadvanta ge to doing this?


<snip>

Yes, you will be excluding some browsers from being able to use the
script without necessarily having a good reason for doing so.

Yes. That's true. Raises the fundamental issue of whether you should design
for graceful degradation or simply ignore older browsers. I'm sure this has
been thrashed out elsewhere.

May have found a second potential disadvantage.
When testing your page from served local web server (not file system) AND
you use the technique of this thread AND
you are referencing a script file from outside the root of your domain,
using the file system (eg file:///C:/Data/...)
THEN
You get errors :(


Security errors is what they should be. It is because you are on the
server localhost (or similar) and you are pulling data from the HD. No
different than the page being on www.sampleDomain.com and trying to get
data from your HD. The solution? Put your script files on the "server"
and address them that way.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 4 '05 #5
Mellow Crow said the following on 11/3/2005 8:21 PM:
Just discovered this technique. Is this old hat? Would there be any
disadvantage to doing this?
Define "old hat" and the age it requires to be considered old hat. As
for the technique of loading JS files on the fly, it is not new. Nowhere
close to new.

<URL:
http://groups.google.com/group/comp....scoring%3Dd%26


Search the archives for "Dynamicall y loading a .js file" and you will
find the above thread in case the URL gets broken. That article is 2 1/2
years old and I was not the first one to start using that method.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 4 '05 #6
Mellow Crow wrote:
Richard Cornford wrote:
Mellow Crow wrote:
Just discovered this technique. Is this old hat?
It is not old hat as such because the number of browsers that
fully support the technique only recently increased to the
point where it could be considered viable in an Internet
context. It has been known, and experimented with, for some
considerable time.


Yes. It's a W3C/standards/"modern" technique so it's new in that
sense.


Browser scripting is about ten years old, and the oldest W3C DOM
standards about 6 years old. How modern is modern?
Would there be any
disadvantage to doing this?

<snip>

Yes, you will be excluding some browsers from being able to
use the script without necessarily having a good reason for
doing so.


Yes. That's true. Raises the fundamental issue of whether
you should design for graceful degradation or simply ignore
older browsers.


Those are not the applicable either/ors in this situation. The most
modern, dynamic, DOM standard and capable web browser can have scripting
turned off. So designing for clean degradation should be necessary in
all open public contexts in order to accommodate even modern browsers in
certain (legitimate and possible) configurations.

But browsers are increasingly appearing on small mobile devices. These
browsers are modern (and more or less standards compliant), but not
necessarily nearly as dynamic as desktop browsers. It may be, and has
been, argued that the need for clean degradation in Internet scripts is
currently increasing as a result.
I'm sure this has been thrashed out elsewhere.

<snip>

It has, but there is no good reason not to state a case and see what
happens. Designing for clean-degradation is very important to the
subject of browser scripting with javascript.

Richard.
Nov 4 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3336
by: Viviana Vc | last post by:
How can I programatically do the equivalent of the following: cacls "C:\Program Files\test" /T /G Everyone:f ? Thanks, Viv
1
3241
by: mr_burns | last post by:
Hi, i was wondering if it is possible to load text into a string from an external text file. the reason is that i have a very large string and it is making my script very messy. also, is it possible to have some dynamic parts of the text from the text file? for example, if i load in a string and there is a part of it that inserts a value from a variable like the following: 'The number of people is ' + var_people_num;
9
6901
by: Charley Kyd | last post by:
I'm a newbie who needs advice about how to use external files of JavaScript code. I spent an hour this afternoon browsing through JavaScript books at the local book store. In about 15 different titles, I found a total of about five pages that covered js files. For all practical purposes, these pages said, "You can use js files. But we won't tell you how." Therefore, I hope someone can answer a few questions about js files... 1....
9
4505
by: fishbaugher | last post by:
I have encountered some interesting crashes lately (Access97). Here is the symptom (after several days of different kinds of rebuilds including import and LoadFromText, all resulting in databases with the same symptoms). 1) Working database, Compile/Save All works, Create MDE works 2) Touch the references (mark a new reference, OK, then Unmark) 3) Create MDE works 4) Compile/Save All works 5) Now try creating MDE from the compiled...
17
2783
by: CES | last post by:
All, I was wondering if their is a way of loading an external script fill from within a script?? <script language="javascript" type="text/javascript"> function test(var){ <script language="javascript" src="../scripts/base.js" type="text/javascript" /> } </script> Obviously this would cause n error but this would give you an idea of what I'm looking to do. I know I can do this with a simple include but...
6
3691
by: windandwaves | last post by:
Hi Folk Some of my clients asked me to create "fancy emails" for them (aka html formatted emails). I know how to make a nice html document, but I had trouble creating a simple way to provide the document to my clients so that they could use it to. I know most of them use Outlook XP or Outlook 2003, so what I created was a page that creates a Visual Basic script that, when saved to the desktop and
3
7721
by: Conrad | last post by:
Hi, it seems that I have the following issue when trying to create a symbolic link within a script: FROM COMMAND LINE: The owner is set to myself. Thus, it works. FROM WEB PAGE: It doesn't work as expected. I know that it runs as one user at the command line and a different user from the web page. Thus, is it possible to do the following within the script:
8
2173
by: Bruce | last post by:
I am using VB in Vs2005. Am I missing something or does VB not have the concept of "builds" (release/debug) like in VC? I wrote an assembly and I would like to have a debug version of the DLL and a release version of the DLL. I would like to create some sample code that demonstrates my assembly in VB and would like to have two builds, one using my debug version and the other using the release version of the assembly. How can I do...
38
4033
by: Neo Geshel | last post by:
I am seeking a method to load one JS file directly into another, *without* having to dynamically write <scripttags. Is there any method whereby I can call only one external JS file using a single <scripttag, but have that external JS file insert into ITSELF the contents of five others? Something like: /*start external.js*/
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10040
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.