Calling External Scripts

S

Smoke

We had a javascript calling a Cold Fusion page (.cfm) and it was working for
2 years. Suddenly yesterday or today its decided it doesn't want to work
anymore. I'm picking up somebody elses code I don't know all of the rules
here.

All of the examples I've found really want .JS files if called with a script
tag, example below.

<script src="http://www.website.com/javascripts/xxx.js">
</script>

Question - is this a hard rule or can you call a file with any extention?

Thanks in advance.
 
L

Lasse Reichstein Nielsen

Smoke said:
We had a javascript calling a Cold Fusion page (.cfm) and it was working for
2 years. Suddenly yesterday or today its decided it doesn't want to work
anymore.

Well, *something* must have changed on the computer. Unless the
offending page code has a time bomb included, you must have changed
either the operating system, the Cold Fusion version, the web serve,
or some library that something depends on.
I'm picking up somebody elses code I don't know all of the rules
here.

Ah. Debugging somebody else's code. Always ... interesting.
All of the examples I've found really want .JS files if called with a script
tag, example below.

<script src="http://www.website.com/javascripts/xxx.js">

This is illegal HTML 4. The "type" attribute is required on script
tags. Add type="text/javascript"
</script>

Question - is this a hard rule or can you call a file with any extention?

That depends on the browser. Technically, there shouldn't be any
restrictions on the name of the file, or on the URL at all (e.g.
"http://www.example.com/foo/" should be legal). You specify the
type of the file in the type attribute and it is given by the server,
so the extension is not important.

However, some browsers, in some cases, try to second guess the type of
file using the extension. The *safest* is to use a recognizable extension
that doesn't match some other type of file.

/L
 
T

Thomas 'PointedEars' Lahn

Smoke said:

That's invalid HTML 4. The `type' attribute is missing here, so the script
could simply be ignored and all the variables and functions it defines could
become undefined in the context of this particular HTML document. Use

<script src="..." type="text/javascript"></script>

instead.


HTH

PointedEars
 
R

Richard Cornford

That depends on the browser. Technically, there shouldn't
be any restrictions on the name of the file, or on the URL
at all (e.g. "http://www.example.com/foo/" should be legal).
You specify the type of the file in the type attribute and
it is given by the server, so the extension is not important.

A while back, in response to a question about having servers send
"text/javascript" content type headers (which apparently have no
official status in HTTP terms), I did some experiments explicitly
setting content type headers from a JavaScript generating JSP script. I
tried a wide range of content type headers including ones that the
browsers would have had an attitude about in any other context, totally
fictitious ones and things like "text/html" & "text/plain". And the
results were that any resource (any file extension, including no
extension at all) referred to in the SRC of a script tag could be sent
with any content type header and so long as what showed up contained
script all of the browsers I tested with happily interpreted and
executed it.
However, some browsers, in some cases, try to second guess
the type of file using the extension. The *safest* is to use
a recognizable extension that doesn't match some other type
of file.

IE is the browser with the reputation for making its own decisions about
how to interpret material it receives, but the above tests included IE
4, 5 and 6 with the results described.

So putting type="text/javascrpt" in the opening script tag is required
for valid HTML 4, but beyond that the only thing that seems to matter is
that what shows up actually contains recognisable JavaScript source
code.

Richard.
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top