473,401 Members | 2,125 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,401 software developers and data experts.

Why people use this style of javascript declaration?

e.g.

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

but not

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

for any reason?

Sep 10 '06 #1
16 1847


ho******@gmail.com wrote:
e.g.

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

but not

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

for any reason?
Most people write HTML 4 and there
<script type="text/javascript" src="js/common.js"></script>
is the proper way.

Some people write XHTML 1 and serve it as text/html and then
<script type="text/javascript" src="js/common.js"></script>
is the proper way too.

If you write XHTML and serve with an XML or XHTML MIME type like
application/xml or text/xml or application/xhtml+xml then you can choose
between the two ways you have shown as then your markup is parsed with
an XML parser and in terms of XML there is no difference between the two
forms, both are allowed.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 10 '06 #2
Martin Honnen wrote on 10 sep 2006 in comp.lang.javascript:
>

ho******@gmail.com wrote:
>e.g.

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

but not

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

for any reason?

Most people write HTML 4 and there
<script type="text/javascript" src="js/common.js"></script>
is the proper way.

Some people write XHTML 1 and serve it as text/html and then
<script type="text/javascript" src="js/common.js"></script>
is the proper way too.
Eh?
If you write XHTML and serve with an XML or XHTML MIME type like
application/xml or text/xml or application/xhtml+xml then you can choose
between the two ways you have shown as then your markup is parsed with
an XML parser and in terms of XML there is no difference between the two
forms, both are allowed.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 10 '06 #3
ho******@gmail.com wrote:
Re: Why people use this style of javascript declaration?

e.g.

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

but not

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

for any reason?
I haven't looked before but this email prompted me to scan through the
doctype definition

<URL: http://www.w3.org/TR/html4/strict.dtd>

Here are a couple relevant parts I gleaned. The <br /element id
defined as empty and so are all the others you see regularly without a
closing tag like <img /and <meta />. The <script></scriptelement is
not defined as empty.

<!ELEMENT BR - O EMPTY -- forced line break -->
<!ATTLIST BR
%coreattrs; -- id, class, style, title --
>
<!ELEMENT SCRIPT - - %Script; -- script statements -->
<!ATTLIST SCRIPT
charset %Charset; #IMPLIED -- char encoding of linked
resource --
type %ContentType; #REQUIRED -- content type of script
language --
src %URI; #IMPLIED -- URI for an external script --
defer (defer) #IMPLIED -- UA may defer execution of
script --
event CDATA #IMPLIED -- reserved for possible future
use --
for %URI; #IMPLIED -- reserved for possible future
use --
>
-Peter

Sep 10 '06 #4


Evertjan. wrote:
Martin Honnen wrote on 10 sep 2006 in comp.lang.javascript:
>>Most people write HTML 4 and there
<script type="text/javascript" src="js/common.js"></script>
is the proper way.

Some people write XHTML 1 and serve it as text/html and then
<script type="text/javascript" src="js/common.js"></script>
is the proper way too.


Eh?
HTML 4 defines its script element here:
<http://www.w3.org/TR/html4/interact/scripts.html#edef-SCRIPT>
clearly saying "Start tag: required, End tag: required".

XHTML 1 has this section <http://www.w3.org/TR/xhtml1/#guidelinesabout
serving XHTML 1 as text/html and section C3 there says:
"Given an empty instance of an element whose content model is not
EMPTY (for example, an empty title or paragraph) do not use the
minimized form (e.g. use <p</pand not <p />)"
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 10 '06 #5
VK
ho******@gmail.com wrote:
<script type="text/javascript" src="js/common.js"></script>
but not
<script type="text/javascript" src="js/common.js" />
for any reason?
Did you try to use it in a document served as text/html? This is the
answer: because it doesn't work :-)

<scripttag requires closing tag. The second option will work only for
a document parsed as XHTML (not HTML). Please note: *parsed* as XHTML
(thus served with the proper Content-Type), not just being called XHTML
in the document head section and/or conforming to XHTML syntax rules.

You may read
<http://groups.google.com/group/comp.infosystems.www.authoring.html/browse_frm/thread/6ff8329925aae8a6/ffe8f9f366be53ad>
if you have patience to follow that long and with numerous OT's
discussion.

Sep 10 '06 #6
ho******@gmail.com wrote:
<script type="text/javascript" src="js/common.js"></script>

but not

<script type="text/javascript" src="js/common.js" />
The latter is an XML empty-element tag so it is not appropriate for use
in a HTML document[1].

Mike

Cross-posted, and follow-ups set, to comp.infosystems.www.authoring.html.
[1] I define a HTML document here to mean any document that is served
with a text/html MIME type, whether it looks like XHTML or not.
Sep 10 '06 #7
ho******@gmail.com wrote:
<script type="text/javascript" src="js/common.js"></script>
but not
<script type="text/javascript" src="js/common.js" />
for any reason?
The latter lacks the required end tag in HTML, is forbidden by Appendix C of
the XHTML 1.0 spec and breaks horribly in MSIE.

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 10 '06 #8

Martin Honnen 寫道:
ho******@gmail.com wrote:
e.g.

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

but not

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

for any reason?

Most people write HTML 4 and there
<script type="text/javascript" src="js/common.js"></script>
is the proper way.

Some people write XHTML 1 and serve it as text/html and then
<script type="text/javascript" src="js/common.js"></script>
is the proper way too.

If you write XHTML and serve with an XML or XHTML MIME type like
application/xml or text/xml or application/xhtml+xml then you can choose
between the two ways you have shown as then your markup is parsed with
an XML parser and in terms of XML there is no difference between the two
forms, both are allowed.

--

Martin Honnen
http://JavaScript.FAQTs.com/
I know I should use, i.e.

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

for HTML or XHTML

but since there is no content inside the tag anyway, what are the
reason behind this style?

thanks.

Sep 11 '06 #9


ho******@gmail.com wrote:

I know I should use, i.e.

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

for HTML or XHTML

but since there is no content inside the tag anyway, what are the
reason behind this style?
The reasons where already given in the answers you got, HTML 4 as an
SGML application defines its syntax rules and requires that the script
element has a start tag and an end tag. XHTML as an XML application has
different rules. If you want to question the reasons of those who
defined those rules then you might want to try your luck in
comp.infosystems.www.authoring.html.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 11 '06 #10
VK
but since there is no content inside the tag anyway, what are the
reason behind this style?

If you want to question the reasons of those who
defined those rules then you might want to try your luck in
comp.infosystems.www.authoring.html.
I say this question more relevant to JavaScript rather then to the HTML
tags as such.

The reason is historical (as many things in HTML/scripting).

Until versions NN3/IE3 the only browser with JavaScript support was
Netscape 2.x, and it did not support external .js files, only scripts
directly inserted into page between <script>...</scripttags.
Respectively <scripttag was added to HTML specs as the one requiring
closing tag.
With versions NN3/IE3 it became possible to use external .js files, but
the paired tag was used as the fall-back option for NN2 users. If both
src attribute and inline content were provided, NN3/IE3 users would get
the external .js file executed and inline content ignored. NN2 users
would get src ignored and inline block executed:

<script language="JavaScript" src="external.js">
window.alert("Your browser doesn't support external scripts");
</script>

(btw it is another FAQ when people are trying to combine both external
and inline scripts in one tag and getting only the external script
executed. If you ever tried it and wondered why then here is the
answer).

By NN4/IE4 the above became a standard with a bunch of legacy scripts
around, so it was too late to change anything.

Hope it helps.

Sep 11 '06 #11
VK said the following on 9/11/2006 9:46 AM:
>>but since there is no content inside the tag anyway, what are the
reason behind this style?
If you want to question the reasons of those who
defined those rules then you might want to try your luck in
comp.infosystems.www.authoring.html.

I say this question more relevant to JavaScript rather then to the HTML
tags as such.
<sarcasm>
The rules of xHTML and HTML are more relevant to JS than to HTML? Wow,
your logic is awesome!
</sarcasm>

Not really, it's just more VK crap noise is all.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 12 '06 #12
VK

Randy Webb wrote:
<sarcasm>
The rules of xHTML and HTML are more relevant to JS than to HTML? Wow,
your logic is awesome!
</sarcasm>
You don't need to try so hard to be a moron on a plain place, you'll
have much better opportunities in the future. The question of how to
insert/link JavaScript code on a web-page is definitely one more
relevant to c.l.j.

This mechanics and historical background are given in my post you
missed to quote properly. Is September some moronic fair here?

Sep 12 '06 #13
ho******@gmail.com wrote:
e.g.

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

but not

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

for any reason?
I've been hunting for the reason we don't do the comment trick to hide
javascript. I can't remember which browser needed this. I think it was
a very old browser.

<script type="text/javascript">
<!--
alert("hi");
-->
</script>

Thanks,
Peter

Sep 24 '06 #14
pe**********@gmail.com wrote:
I've been hunting for the reason we don't do the comment trick to hide
javascript.
In XHTML? Because it comments the JavaScript out (since the content model of
<scriptelements has changed).

In HTML? Because browsers which need it have much bigger problems (such as
supporting HTTP 1.1).
I can't remember which browser needed this. I think it was
a very old browser.
Netscape 2 era IIRC.
--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 24 '06 #15
pe**********@gmail.com wrote:
<snip>
I've been hunting for the reason we don't do the comment
trick to hide javascript.
Did you find any justification for using it that has had any validity in
the last half decade? Sometime you don't do something became there is no
reason for ding it, rather than that you cannot find a reason for not
ding it.
I can't remember which browser needed this.
Browsers pre-dating and contemporary with Netscape 2 would have no idea
what a SCRIPT element was and so would tend to treat their contents as
text to be displayed. Browsers produced after that time would have no
problem knowing to ignore SCRIPT elements even if they could not handle
scripts themselves.
I think it was a very old browser.
Currently version 4 era browsers are considered very old (if not
dinosaurs), and even the preceding generation did not need 'script
hiding'.
<script type="text/javascript">
<!--
alert("hi");
-->
Since that the content of an HTML script element is script source code
the <!-- character sequence cannot be interpreted as mark-up in that
context. To enable script hiding to work at all (that is, not to cause
syntax errors in browsers that understand scripts) the <!-- sequences is
treated as an alternative opening single line comment token (alternative
to //). This is not true of the -->, which could not be treated
specially as it is a valid sequence of javascript operators ( x-->y -
would be a 'is x greater than y' expression with post-decrement of x).
The 'script hiding' tended to get around that by hiding the --sequence
in a javascript single line comment. I.E. writing //--instead of
just -->. Error correction in IE (and probably some other browsers) will
let you get away with just --in some contexts, but your formulation
above will certainly result in script syntax errors in some browsers.

Richard.

Sep 24 '06 #16
In article <ef*******************@news.demon.co.uk>, Richard Cornford
<Ri*****@litotes.demon.co.ukwrites

<snip>
>Browsers pre-dating and contemporary with Netscape 2 would have no idea
what a SCRIPT element was and so would tend to treat their contents as
text to be displayed. Browsers produced after that time would have no
problem knowing to ignore SCRIPT elements even if they could not handle
scripts themselves.
<snip>

My modern e-mail/news reader doesn't understand SCRIPT elements either,
but that's deliberate policy. It means that invitations to re-enter my
bank details look like a suspicious mess. Oh, what a shame! If I want to
view an HTML e-mail in all its glory I can ask for it to be displayed in
a proper browser.

So the rule nowadays is that displaying scripts as text is the reader's
choice; we shouldn't do anything to override that choice. This is a bit
stronger than saying there's no point hiding scripts any more.

John
--
John Harris
Sep 27 '06 #17

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

Similar topics

7
by: Bura Tino | last post by:
Hi, Going forward, what's better to use <td height="20"> or <td style="height:20;">
3
by: macgyver | last post by:
This is a strange question, and I think the answer is NO, but I am asking anyway. I am a member of a website which allows us to alter our member profiles. Using css in the middle of the profile...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
28
by: Michael B. | last post by:
I tend to use rather descriptive names for parameters, so the old style of declaration appeals to me, as I can keep a declaration within 80 chars: void * newKlElem...
63
by: Papadopoulos Giannis | last post by:
Which do you think is best? 1. a) type* p; b) type *p; 2. a) return (var); b) return(var); c) return var;
7
by: G Fernandes | last post by:
Is the following an old-style(K&R) function definition or a new style(C89)? int (length, factor, multiple) { /* ... code ... */ return length; }
3
by: delraydog | last post by:
I'm writing a reusable JavaScript library which needs to set certain styles in a document. The document may have an existing stylesheet definition either by a link or by an existing stylesheet...
3
by: alexjaquet | last post by:
Hi, I've in my web pages an affectation to this property but it's doesn't work (same for all the others properties I'm trying to update): here is the complete function I call on mouseover : ...
100
by: Angel Tsankov | last post by:
Can someone recommend a good source of C/C++ coding style. Specifically, I am interested in commenting style and in particular how to indent comments and the commented code, rather than when to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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 projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.