![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
(Request for Discussion) I've put together a guide that I hope will help novice coders avoid the same hair pulling that I went through. |
#3
| |||
| |||
|
|
On Tue, 01 Jan 2008 05:28:51 -0500, Jeremy J Starcher wrote: (Request for Discussion) I've put together a guide that I hope will help novice coders avoid the same hair pulling that I went through. |
#4
| |||||||
| |||||||
|
|
On Jan 1, 6:37 pm, Jeremy J Starcher <r3... (AT) yahoo (DOT) spam.me.not.com wrote: On Tue, 01 Jan 2008 05:28:51 -0500, Jeremy J Starcher wrote: (Request for Discussion) I've put together a guide that I hope will help novice coders avoid the same hair pulling that I went through. For the language="javascript" issue you recommended: script type="text/javascript"></script |
|
Personally I'd recommend just using: script></script |
|
Partly because "text/javascript" is an invalid MIME type, |
|
it should be "application/javascript". |
|
But "application/javascript" is invalid HTML, |
|
it MUST be "text/javascript". |
|
So best to avoid it altogether and save keystrokes/bytes. |
#5
| ||||||
| ||||||
|
|
For the language="javascript" issue you recommended: script type="text/javascript"></script Personally I'd recommend just using: script></script |
|
Partly because "text/javascript" is an invalid MIME type, |
|
it should be "application/javascript". |
|
But "application/javascript" is invalid HTML, |
|
it MUST be "text/javascript". |
|
So best to avoid it altogether and save keystrokes/bytes. |
#6
| |||
| |||
|
|
Personally I'd recommend just using: script></script Partly because "text/javascript" is an invalid MIME type, it should be "application/javascript". But "application/javascript" is invalid HTML, it MUST be "text/javascript". So best to avoid it altogether and save keystrokes/bytes. |
#7
| |||||||||
| |||||||||
|
|
I've put together a guide that I hope will help novice coders avoid the same hair pulling that I went through. I'm open for comments about it. Have I missed the mark on a point or two? Have I overlooked something? |
|
Using the pseudo-protocol javascript in the href is never valid. Not only is such code not valid HTML, [...] |
|
it cannot provide a fallback to browsers not running Javascript. |
|
Using eval to parse JSON works well. While there are some security concerns, they can be easily addressed. |
|
Internet Explorer provides a way to identify itself that does not interfer with other browsers. Some web developers use this to work around bugs in IE's handling of style sheets or to import compability code. Other web developers regard this is an evil crutch. |
|
Is my basic goal flawed? |
|
Is code bad in so many different ways |
|
that I should just pack up shop and forget this? |
|
Or did I do a smashing bang-up job that will keep the new coders away from the horrors of most online examples and finally end c.l.j's favorite hobby?(*) |
#8
| |||||||||||||||
| |||||||||||||||
|
|
Jeremy J Starcher wrote: Have I missed the mark on a point or two? Have I overlooked something? Plenty. 1. "Depreciated script tag usage" a. The word you were looking for is _deprecated_, not "depreciated". |
|
b. The term you were looking for is `script' _element_, not "tag". Elements consist of tags (start tag, close tag) and content: http://www.w3.org/TR/REC-html40/intr...t.html#h-3.2.1 |
|
c. Your example `script' elements are empty where they should have content. At least that should be indicated in some way. |
|
d. "JavaScript1.2" actually means something in NN4; ask Google. I have never seen anyone using "JavaScript1.3", though. |
|
2. 'Using "href:javascript"' | Using the pseudo-protocol javascript in the href is never valid. Not | only is such code not valid HTML, [...] Wrong. The value of the `href' attribute is of type URI. If `javascript:' syntax would be written as an URI, it would certainly be valid there. One point of recommending against `javascript:' there is that | it cannot provide a fallback to browsers not running Javascript. There are other points that I have also mentioned in my FAQ notes last year. There are also exceptions to be made in special cases. |
|
3. "Excessive use document.write" should read "Excessive use *of* document.write()". |
|
A recommendation for a viable alternative is missing. Consider this: script type="text/javascript" if (NN4 || IE4) { document.write( new Array( '<ul>', ' <li><a href="Search.html">Search<\/a><\/li>', ' <li><a href="Order.html">Order<\/a><\/li>'); ' <li><a href="Help.html">Help<\/a><\/li>'); '<\/ul>' ).join("") ); } /script |
|
4. 'Not ending lines in a semi-colon ";"' The argument in favor of the trailing `;' is flawed in two regards: a) not every line should be ended with a semicolon but every *statement*; |
|
b) minifiers should not be used. See previous discussions. |
|
5. "Use of eval" | Using eval to parse JSON works well. While there are some security | concerns, they can be easily addressed. There are two other uses where using eval() is considered appropriate. One is making arbitrary computations with user input, |
|
the other is hiding code from script engines that consider it to be syntactically invalid because they do not support the corresponding language feature. |
|
A reasoning for the statement that the security concerns could be easily addressed is missing. |
|
6. "Browser sniffing" You describe the goal of that -- "to tell which browser the code is running on" to be "good", and I don't agree. Web developers should avoid writing for a specific user agent. |
|
7. "Web pages that do not include a DOCTYPE and/or do not validate" | Internet Explorer provides a way to identify itself that does not | interfer with other browsers. Some web developers use this to work | around bugs in IE's handling of style sheets or to import | compability code. Other web developers regard this is an evil crutch. The argument against Conditional Comments is not sound, at least not for IE-specific workarounds. CCs are valid SGML markup. |
|
PointedEars |
#9
| |||
| |||
|
|
On Tue, 01 Jan 2008 18:01:51 +0100, Thomas 'PointedEars' Lahn wrote: Jeremy J Starcher wrote: Have I missed the mark on a point or two? Have I overlooked something? Plenty. 1. "Depreciated script tag usage" a. The word you were looking for is _deprecated_, not "depreciated". Absolutely correct. Thought I spell-checked everything. I'll fix that. |
#10
| |||||||
| |||||||
|
|
1. "Depreciated script tag usage" a. The word you were looking for is _deprecated_, not "depreciated". |
|
b. The term you were looking for is `script' _element_, not "tag". Elements consist of tags (start tag, close tag) and content: http://www.w3.org/TR/REC-html40/intr...t.html#h-3.2.1 |
|
c. Your example `script' elements are empty where they should have content. At least that should be indicated in some way. |
|
One point of recommending against `javascript:' there is that | it cannot provide a fallback to browsers not running Javascript. There are other points that I have also mentioned in my FAQ notes last year. There are also exceptions to be made in special cases. |
|
3. "Excessive use document.write" should read "Excessive use *of* document.write()". |
|
A recommendation for a viable alternative is missing. |
|
Or did I do a smashing bang-up job that will keep the new coders away from the horrors of most online examples and finally end c.l.j's favorite hobby?(*) Hardly. |
![]() |
| Thread Tools | |
| Display Modes | |
| |