Connecting Tech Pros Worldwide Forums | Help | Site Map

script tagq

lotusny78@yahoo.com
Guest
 
Posts: n/a
#1: Dec 7 '05
Is it an error to have a non-existent filname in:
<script src="scriptfile.js"></script>

I'm using a templating engine to compile the page, so "scriptfile.js"
will be "" if there is no javascript for the page.

Would it be better to load in the javascript with every page? Would it
be cached?


Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#2: Dec 7 '05

re: script tagq


"lotusny78@yahoo.com" <lotusny78@yahoo.com> writes:
[color=blue]
> Is it an error to have a non-existent filname in:
> <script src="scriptfile.js"></script>[/color]

Try it. Make a page and submit it to <URL:http://validator.w3.org/>.

I guess that it is not an error in itself, but that it means to
load the current page as a javascript file, which is likely to
give rise to script errors.

It is invalid HTML to have a script element without the type
attribute, so it should be:

<script type="text/javascript" src="scriptfile.js"></script>
[color=blue]
> I'm using a templating engine to compile the page, so "scriptfile.js"
> will be "" if there is no javascript for the page.[/color]

Change the template so the entire script element is omitted if there
is no javascript. That should be very simple. IF it isn't, you need a
better template engine.
[color=blue]
> Would it be better to load in the javascript with every page? Would it
> be cached?[/color]

It will probably be cached, if it is the same file for all pages that
use Javascript, *and* the server doesn't set any "don't cache" headers
when it sends it.

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Richard Cornford
Guest
 
Posts: n/a
#3: Dec 7 '05

re: script tagq


lotusny78@yahoo.com wrote:[color=blue]
> Is it an error to have a non-existent filname in:
> <script src="scriptfile.js"></script>[/color]

That depends on what you consider an error. The browser will make a
request to the server whether the file exists or not. It may (should)
get an HTTP 404 error back from the server, but it invariable takes the
server longer to work out that it cannot find a resource than it does
for it to return a real resource.
[color=blue]
> I'm using a templating engine to compile the page,
> so "scriptfile.js" will be "" if there is no javascript
> for the page.[/color]

An empty URL is a relative URL that refers to the start of the current
document. So that is a URL of a resource that does exist, but is
probably HTML and so will generate a syntax error when interpreted as
javascript.
[color=blue]
> Would it be better to load in the javascript with
> every page?[/color]

What javascript?
[color=blue]
> Would it be cached?[/color]

Javascript referenced by SRC attributes in SCRIPT elements is a normal
candidate for client-side caching, assuming it is sent with reasonable
HTTP headers.

Richard.


Closed Thread