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


Groups > comp.lang.javascript > #24743 > unrolled thread

strange splits

Started byRoedy Green <see_website@mindprod.com.invalid>
First post2014-06-11 12:41 -0700
Last post2014-06-12 11:49 +0100
Articles 8 — 7 participants

Back to article view | Back to comp.lang.javascript


Contents

  strange splits Roedy Green <see_website@mindprod.com.invalid> - 2014-06-11 12:41 -0700
    Re: strange splits John C <rescattered@gmail.com> - 2014-06-11 13:06 -0700
    Re: strange splits Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2014-06-12 09:05 +0200
      Re: strange splits "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-12 10:18 +0200
        Dynamically inserting script elements (was: strange splits) Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-14 17:55 +0200
          Re: Dynamically inserting script elements Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-14 21:43 +0200
            Re: Dynamically inserting script elements Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-16 19:36 +0200
      Re: strange splits John Harris <niam@jghnorth.org.uk.invalid> - 2014-06-12 11:49 +0100

#24743 — strange splits

FromRoedy Green <see_website@mindprod.com.invalid>
Date2014-06-11 12:41 -0700
Subjectstrange splits
Message-ID<q3chp9p46ron6497svevkvlurllkeh26ci@4ax.com>
Vendors give me snippets of JavaScript to insert in my webpages.

Sometimes I see code like this:

   document.write("<sc"+"ript type='text/javascript'...

Why don't they write that as:

   document.write("<script type='text/javascript'...
-- 
Roedy Green Canadian Mind Products http://mindprod.com
In former times, people who craved absolute power became gangsters.
Today, they become computer programmers.

[toc] | [next] | [standalone]


#24744

FromJohn C <rescattered@gmail.com>
Date2014-06-11 13:06 -0700
Message-ID<b823b69d-e8c7-4379-96c6-824c37ba107b@googlegroups.com>
In reply to#24743
On Wednesday, June 11, 2014 3:41:45 PM UTC-4, Roedy Green wrote:
> Vendors give me snippets of JavaScript to insert in my webpages.
> 
> 
> 
> Sometimes I see code like this:
> 
> 
> 
>    document.write("<sc"+"ript type='text/javascript'...
> 
> 
> 
> Why don't they write that as:
> 
> 
> 
>    document.write("<script type='text/javascript'...
> 
> -- 
> 
> Roedy Green Canadian Mind Products http://mindprod.com
> 
> In former times, people who craved absolute power became gangsters.
> 
> Today, they become computer programmers.

Just guessing, but it seems like an attempt to bypass some security software that doesn't like scripts which generate scripts.

[toc] | [prev] | [next] | [standalone]


#24755

FromHans-Georg Michna <hans-georgNoEmailPlease@michna.com>
Date2014-06-12 09:05 +0200
Message-ID<c7kip95ijtb9k8v58ka90k02396g5e6fpv@4ax.com>
In reply to#24743
On Wed, 11 Jun 2014 12:41:45 -0700, Roedy Green wrote:

>Vendors give me snippets of JavaScript to insert in my webpages.
>
>Sometimes I see code like this:
>
>   document.write("<sc"+"ript type='text/javascript'...
>
>Why don't they write that as:
>
>   document.write("<script type='text/javascript'...

That is because under some circumstances the <script ... tag may
be processed before the document.write(... is executed. The
split prevents the recognition of the <script ... tag.

Hans-Georg

[toc] | [prev] | [next] | [standalone]


#24759

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-06-12 10:18 +0200
Message-ID<XnsA34A68D747DAEeejj99@194.109.133.133>
In reply to#24755
Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> wrote on 12 jun 2014 
in comp.lang.javascript:

> On Wed, 11 Jun 2014 12:41:45 -0700, Roedy Green wrote:
> 
>>Vendors give me snippets of JavaScript to insert in my webpages.
>>
>>Sometimes I see code like this:
>>
>>   document.write("<sc"+"ript type='text/javascript'...
>>
>>Why don't they write that as:
>>
>>   document.write("<script type='text/javascript'...
> 
> That is because under some circumstances the <script ... tag may
> be processed before the document.write(... is executed. The
> split prevents the recognition of the <script ... tag.

Indeed, that is what I read over and over again.
Is it [still] true in modern browsers?

Questions:
When will this script execute? 
Immediately?

Meseems the whole approach only makes sense for 
adding an external script by a script.

=========================

Now when the page has finished loading,
using the DOM to add such script node,
by onload = .. or interactive like onclick = ...,
seems the way to go:

var s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'http://????/???.js';
document.body.appendChild(s);

Questions:
When will this execute? 
Immediately?
Only after the appendChild()?
Is the appendChild() even necessary for execution?

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#24834 — Dynamically inserting script elements (was: strange splits)

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2014-06-14 17:55 +0200
SubjectDynamically inserting script elements (was: strange splits)
Message-ID<539c706d$0$6607$9b4e6d93@newsspool4.arcor-online.net>
In reply to#24759
Evertjan. wrote:

> var s = document.createElement('script');
> s.type = 'text/javascript';
> s.src = 'http://????/???.js';
> document.body.appendChild(s);
> 
> Questions:
> When will this execute? 
> Immediately?
> Only after the appendChild()?
> Is the appendChild() even necessary for execution?

I don't know if there is any standard specification of the behavior, but
a quick test on current stable Chrome required to insert the script
element into the DOM before the script was loaded.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#24837 — Re: Dynamically inserting script elements

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-06-14 21:43 +0200
SubjectRe: Dynamically inserting script elements
Message-ID<2026431.rsCDfxh4iT@PointedEars.de>
In reply to#24834
Christoph Michael Becker wrote:

> I don't know if there is any standard specification of the behavior, but
> a quick test on current stable Chrome required to insert the script
> element into the DOM before the script was loaded.

There is something close that specifies exactly this behavior:

<http://www.w3.org/TR/2014/CR-html5-20140204/scripting-1.html#the-script-element>

I think it is only logical that the script element resource would not be 
parsed before it is inserted because a client-side script may depend on 
symbols defined in other scripts that may need to be included dynamically as 
well.

However, it should be noted that loading script elements this way is 
asynchronous: you cannot assume that the symbols in the loaded script are 
immediately available afterwards.  It is therefore good that HTML5 CR also 
specifies events like “beforescriptexecute”, “afterscriptexecute” and, most 
notably, “load”, for the “script” element.  It would appear that, finally, 
there is going to be a standards-compliant way to load script resources 
dynamically without resorting to hacks and XHR.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#24889 — Re: Dynamically inserting script elements

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2014-06-16 19:36 +0200
SubjectRe: Dynamically inserting script elements
Message-ID<539f2afe$0$6612$9b4e6d93@newsspool4.arcor-online.net>
In reply to#24837
Thomas 'PointedEars' Lahn wrote:

> Christoph Michael Becker wrote:
> 
>> I don't know if there is any standard specification of the behavior, but
>> a quick test on current stable Chrome required to insert the script
>> element into the DOM before the script was loaded.
> 
> There is something close that specifies exactly this behavior:
> 
> <http://www.w3.org/TR/2014/CR-html5-20140204/scripting-1.html#the-script-element>

Indeed.  Thanks.

> I think it is only logical that the script element resource would not be 
> parsed before it is inserted because a client-side script may depend on 
> symbols defined in other scripts that may need to be included dynamically as 
> well.

ACK

> However, it should be noted that loading script elements this way is 
> asynchronous: you cannot assume that the symbols in the loaded script are 
> immediately available afterwards.  It is therefore good that HTML5 CR also 
> specifies events like “beforescriptexecute”, “afterscriptexecute” and, most 
> notably, “load”, for the “script” element.

Thanks.  I was not aware of these events.

>                                             It would appear that, finally, 
> there is going to be a standards-compliant way to load script resources 
> dynamically without resorting to hacks and XHR.

ACK

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#24760

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2014-06-12 11:49 +0100
Message-ID<9c1jp95klhlbl89ek7epvvoh2kaunqie03@4ax.com>
In reply to#24755
On Thu, 12 Jun 2014 09:05:12 +0200, Hans-Georg Michna
<hans-georgNoEmailPlease@michna.com> wrote:

>On Wed, 11 Jun 2014 12:41:45 -0700, Roedy Green wrote:
>
>>Vendors give me snippets of JavaScript to insert in my webpages.
>>
>>Sometimes I see code like this:
>>
>>   document.write("<sc"+"ript type='text/javascript'...
>>
>>Why don't they write that as:
>>
>>   document.write("<script type='text/javascript'...
>
>That is because under some circumstances the <script ... tag may
>be processed before the document.write(... is executed. The
>split prevents the recognition of the <script ... tag.

What the current draft of the HTML 5 standard says is :

"The easiest and safest way to avoid the rather strange restrictions
described in this section is to always escape "<!--" as "<\!--",
"<script" as "<\script", and "</script" as "<\/script" when these
sequences appear in literals in scripts (e.g. in strings, regular
expressions, or comments)"

  John

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web