471,873 Members | 1,007 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Calling External Scripts

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.
Jul 20 '05 #1
4 3870
Hi!

You can call file with any extension as long as
this file output correct javascript.

For example - no correct javascript here
http://www.website.com/javascripts/xxx.js

--
Sergey.
http://www.takereal.com/freelance/

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.

Jul 20 '05 #2
"Smoke" <sm***@xatrium.com> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
Smoke wrote:
<script src="http://www.website.com/javascripts/xxx.js">
</script>


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

Jul 20 '05 #4
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:y8**********@hotpop.com...
<snip>
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.


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.
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by bba | last post: by
10 posts views Thread by Pasquale | last post: by
8 posts views Thread by Flip | last post: by
10 posts views Thread by Stefan Weber | last post: by
3 posts views Thread by Anthony Smith | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

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.