Calling External Scripts

Discussion in 'Javascript' started by Smoke, Oct 22, 2003.

  1. Smoke

    Smoke Guest

    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.
    Smoke, Oct 22, 2003
    #1
    1. Advertising

  2. 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.
    >
    >
    Sergey I.Grachyov, Oct 22, 2003
    #2
    1. Advertising

  3. "Smoke" <> 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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Oct 22, 2003
    #3
  4. 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
    Thomas 'PointedEars' Lahn, Oct 23, 2003
    #4
  5. "Lasse Reichstein Nielsen" <> wrote in message
    news:...
    <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.
    Richard Cornford, Oct 23, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    320
  2. Jan Danielsson
    Replies:
    8
    Views:
    613
    Mike Meyer
    Jul 22, 2005
  3. Jp Calderone
    Replies:
    0
    Views:
    445
    Jp Calderone
    Jul 21, 2005
  4. davidj411
    Replies:
    0
    Views:
    483
    davidj411
    Jun 27, 2008
  5. Replies:
    13
    Views:
    516
    Anno Siegel
    Sep 10, 2007
Loading...

Share This Page