473,412 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Include javascript files

Hi,
I have some questions regarding including javascript files.

<head>
<script src="file1.js" type="text/javascript"></script>
<script src="file2.js" type="text/javascript"></script>
</head>

Is it safe to assume that file1.js is always completely before any
statement is executed in file2.js?

One other question is if it is possible to include a javascript file,
but not getting an error about it if this file does not exist (in IE6,
Firefox and other modern browsers)?

Robert.
Mar 22 '06 #1
4 1726

Robert wrote:
Hi,
I have some questions regarding including javascript files.

<head>
<script src="file1.js" type="text/javascript"></script>
<script src="file2.js" type="text/javascript"></script>
</head>

Is it safe to assume that file1.js is always completely before any
statement is executed in file2.js?
Probably not always. Suppose file one contains a time delay of several
seconds and then uses document.write to write some data or code that
will be called for at once when you reach file2.
One other question is if it is possible to include a javascript file,
but not getting an error about it if this file does not exist (in IE6,
Firefox and other modern browsers)?


See http://www.cwdjr.net/test/jsgroup.html . This has a reference to an
external script at http://www.hell.net/fireandsmoke.js. I get no error
message on Firefox or at the W3C validator. I have not had time to try
other browsers yet.

Mar 22 '06 #2
Robert said the following on 3/22/2006 10:29 AM:
Hi,
I have some questions regarding including javascript files.

<head>
<script src="file1.js" type="text/javascript"></script>
<script src="file2.js" type="text/javascript"></script>
</head>

Is it safe to assume that file1.js is always completely before any
statement is executed in file2.js?

One other question is if it is possible to include a javascript file,
but not getting an error about it if this file does not exist (in IE6,
Firefox and other modern browsers)?


If you try to load an external file in IE6 that doesn't exist then about
95% of the time you are going to get an "Invalid Character" syntax error.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 22 '06 #3
Randy Webb wrote:
Robert said the following on 3/22/2006 10:29 AM:
One other question is if it is possible to include a javascript file,
but not getting an error about it if this file does not exist (in IE6,
Firefox and other modern browsers)?


If you try to load an external file in IE6 that doesn't exist then about
95% of the time you are going to get an "Invalid Character" syntax error.


Yes I know, that's why I ask :)
Mar 22 '06 #4
Robert said the following on 3/22/2006 4:46 PM:
Randy Webb wrote:
Robert said the following on 3/22/2006 10:29 AM:
One other question is if it is possible to include a javascript file,
but not getting an error about it if this file does not exist (in
IE6, Firefox and other modern browsers)?


If you try to load an external file in IE6 that doesn't exist then
about 95% of the time you are going to get an "Invalid Character"
syntax error.


Yes I know, that's why I ask :)


It gives the same behavior if you try to dynamically create the script
element as well:

oScript = document.createElement('script');
oScript.src='fakeJSFile.js';
document.getElementsByTagName('head')[0].appendChild(oScript);

Invalid Character error.

You could try retrieving the file with an XMLHTTPRequest object but that
seems like trying to use a sledgehammer to install trim in your house -
overkill.

Typically, you will end up better off not trying to cope with it and let
the error message be an indication of filename/path problems to the
author. If you are retrieving the files from another server, retrieve
them using your own server and then serve it to the browser. If the file
doesn't exist on the remote server, then your server can let the browser
know that and the user never gets an error from a non-existent file.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 22 '06 #5

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

Similar topics

21
by: Peter Bassett | last post by:
I have a .shtml file, that displays photos, in which I wish to pass some functionality off to an Include file for reusability purposes. Unfortunately, it's not working. Here is a portion of the...
22
by: Weston C | last post by:
I know of course that you can use <script src=""></script> in an HTML document to include javascript code you don't want to spill all over the page. I'm wondering if there's a way to include...
4
by: JP SIngh | last post by:
Hi All I want to include javascript files based on the user location which I store in a session variable upon user login. The original code was like this <SCRIPT language=JavaScript...
17
by: lallous | last post by:
Hello Sometimes, I don't know when exactly, when I try to include an external js file as: <script src='myfile.js'></script> that .js file goes not included in some cases!! To solve it, I...
7
by: Fabri | last post by:
I'm trying to develop a way to include static files in htm pages with javascript. I'm trying to use XMLHTTP object this way: ...
3
by: Brit | last post by:
Hello, I have been trying to include a js file from within another js file. I can get this to work for firefox, but not i.e. What I have is a.html ... <script language='JavaScript'...
3
by: John Yopp | last post by:
I seem to be have problems with what appears to be variable scoping. If I define a constant in my main HTML page, I do not seem to be able to reference it within functions in JavaScript include...
2
by: William van Zwanenberg | last post by:
Hi there, I wonder if you guys can help. I'm currently experiencing some coding problems what with trying to use PHP and javascript in tandem. What I'm ultimately trying to achieve is use...
1
by: mtek | last post by:
Does Javascript support include files? I have some functions that I need in 4 pages with Javascript. Can I somehow include that data by using a general include file? All of the Javascript is...
2
by: =?Utf-8?B?UGFi?= | last post by:
I am developing the web controls and try to include all client files: scripts, styles, etc in an assembly as resource common way like: , and use ClientScriptManager class. I have faced a problem...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.