Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #22411

Re: Javascript Help Needed

Message-ID <2691359.uFm2ZBFIHE@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-12-26 07:38 +0100
Subject Re: Javascript Help Needed
Newsgroups comp.lang.javascript
References <6h5uu.25363$gh2.7307@fx24.iad> <l9colr$do9$2@dont-email.me> <52b9f810$0$9502$9b4e6d93@newsspool1.arcor-online.net>

Show all headers | View raw


Christoph Michael Becker wrote:

> Denis McMahon wrote:
>> I suggest that you put all your code in a single script section in the
>> head of the document,

… thereby, *in general*, *slowing down* display and causing all kinds of 
other problems (IOW, bad advice) …

>> that you don't use the "language" attribute for the
>> script section, but instead use the type attribute:
>> type="text/javascript"
>> 
>> Ignore any elf-like apparition that tries to tell you this is wrong, and
>> instead search the web to find out why this is right.

Unsurprisingly, the Web tells why the former is, in general, wrong, and the 
latter is correct.

<https://developers.google.com/speed/pagespeed/>
 
> It is absolutely fine to omit the type attribute, AFAIK.  The only
> reason for using it, is to satisfy HTML 4.x[1] and XHTML 1.x; HTML5 is
> most likely (it is still a CR) going to drop this requirement[2].

It depends on how compatible you want to be and what programming languages 
you are using in the document; see also the testcase referred in 
<http://stackoverflow.com/a/7227303/855543> (there will be a new URI for 
it).

>> Later on you may wish to separate your js code and data, and possibly
>> have some server side system that automatically generates new data files
>> when you update some set of master shipping cost tables.
>> 
>> You have unescaped ampersands in your countries option list, and your
>> innerhtml code includes html closing tags which it is usually a good idea
>> to split up, eg instead of:
>> 
>> blah.innerHTML += "</B>";
>> 
>> use something like:
>> 
>> blah.innerHTML += "<"+"/"+"B>";
>> 
>> to avoid any sequence of '<' + '/' + letter occurring inside the script
>> tags, as these may confuse the rendering engine.
> 
> A simpler and more efficient solution to comply with HTML parsers (which
> might consider </ as introducing a closing tag) is:

The proper terms are _end tag_ and End Tag Open (ETAGO) delimiter, 
respectively.  ETAGO in script code is only necessary to be escaped if the 
code is in an HTML < 5 document.

Nowadays the easiest and – for several reasons – recommended way to work 
around this is to include a script resource.  In my experience, over time 
inline script code soon grows too much so that it is moved to an included 
script resource.  There are other potential advantages of the latter, such 
as parallel loading and better editor support.  This application, being 
small, and the script code limited to a single purpose, may be an exception.
 
>   blah.innerHTML += "<\/B>"
> 
> (Of course, one should preferably build up the value of the innerHTML
> property in advance.)

A solution relying on “innerHTML” etc. alone is not accessible as it will 
not work if a script engine is not used.

> [1] <http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.1>
> [2] <http://www.w3.org/TR/html5/scripting-1.html#the-script-element>

Read more carefully before you cite:

<http://www.w3.org/TR/2012/CR-html5-20121217/syntax.html#syntax>
<http://www.w3.org/TR/2012/CR-html5-20121217/syntax.html#script-data-state>

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Javascript Help Needed Jim Rojas <jrojas@tech-man.com> - 2013-12-23 20:17 -0500
  Re: Javascript Help Needed "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-24 09:17 +0100
    Re: Javascript Help Needed Jim Rojas <jrojas@tech-man.com> - 2013-12-24 10:01 -0500
      Re: Javascript Help Needed Jim Rojas <jrojas@tech-man.com> - 2013-12-24 10:02 -0500
      Re: Javascript Help Needed "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-24 18:11 +0100
        Re: Javascript Help Needed Jim Rojas <jrojas@tech-man.com> - 2013-12-24 12:24 -0500
          Re: Javascript Help Needed "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-24 19:03 +0100
          Re: Javascript Help Needed Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-24 19:18 +0000
    Re: Javascript Help Needed Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-25 23:06 +0000
  Re: Javascript Help Needed Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-24 19:52 +0000
    Re: Javascript Help Needed Jim Rojas <jrojas@tech-man.com> - 2013-12-24 15:02 -0500
      Re: Javascript Help Needed Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-24 22:07 +0100
      Re: Javascript Help Needed Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-25 02:16 +0000
        Re: Javascript Help Needed Jim Rojas <jrojas@tech-man.com> - 2013-12-24 21:48 -0500
      Re: Javascript Help Needed Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-25 23:05 +0000
    Re: Javascript Help Needed Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-24 22:09 +0100
      Re: Javascript Help Needed Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-25 01:51 +0000
      Re: Javascript Help Needed Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-26 07:38 +0100
        Re: Javascript Help Needed Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-26 10:42 +0100
          Re: Javascript Help Needed Jim Rojas <jrojas@tech-man.com> - 2013-12-26 13:14 -0500
        Re: Javascript Help Needed Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-27 22:49 +0100
          Re: Javascript Help Needed Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-27 23:25 +0100

csiph-web