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


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

onload and order

Started byAndrew Poulos <ap_prog@hotmail.com>
First post2013-11-27 08:24 +1100
Last post2013-11-28 09:44 +1100
Articles 8 — 4 participants

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


Contents

  onload and order Andrew Poulos <ap_prog@hotmail.com> - 2013-11-27 08:24 +1100
    Re: onload and order Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-26 23:06 +0100
      Re: onload and order Andrew Poulos <ap_prog@hotmail.com> - 2013-11-27 10:15 +1100
        Re: onload and order Andrew Poulos <ap_prog@hotmail.com> - 2013-11-27 11:35 +1100
          Re: onload and order Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-27 01:39 +0100
    Re: onload and order Archenoth <Archenoth@live.something> - 2013-11-26 22:47 -0600
    Re: onload and order John Harris <niam@jghnorth.org.uk.invalid> - 2013-11-27 15:18 +0000
      Re: onload and order Andrew Poulos <ap_prog@hotmail.com> - 2013-11-28 09:44 +1100

#22188 — onload and order

FromAndrew Poulos <ap_prog@hotmail.com>
Date2013-11-27 08:24 +1100
Subjectonload and order
Message-ID<D-adnXLr779cjAjPnZ2dnUVZ_vmdnZ2d@westnet.com.au>
I have a page laid out like this

<!DOCTYPE html>
<html>
<head>
...
<script type="text/javascript" src="scripts/a.js"></script>
...
</head>
<body>
...
<script type="text/javascript">
   // b
</script>
...
</body>
</html>

"a.js" has a window.onload

Interestingly Chrome and Opera run the code at "b" after the onload is 
triggered but only if the page is on a web server. If the page is on my 
local file system the code at "b" runs first.

Andrew Poulos

[toc] | [next] | [standalone]


#22189

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-11-26 23:06 +0100
Message-ID<1669404.HQe8P1OAMC@PointedEars.de>
In reply to#22188
Andrew Poulos wrote:

> I have a page laid out like this
> 
> <!DOCTYPE html>
> <html>
> <head>
> ...
> <script type="text/javascript" src="scripts/a.js"></script>
> ...
> </head>
> <body>
> ...
> <script type="text/javascript">
>    // b
> </script>
> ...
> </body>
> </html>
> 
> "a.js" has a window.onload
> 
> Interestingly Chrome and Opera run the code at "b" after the onload is
> triggered but only if the page is on a web server. If the page is on my
> local file system the code at "b" runs first.

“http://” vs. “file://”?

Which versions?

-- 
PointedEars

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

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


#22191

FromAndrew Poulos <ap_prog@hotmail.com>
Date2013-11-27 10:15 +1100
Message-ID<M7OdndhjZMtJtgjPnZ2dnUVZ_rKdnZ2d@westnet.com.au>
In reply to#22189
On 27/11/2013 9:06 AM, Thomas 'PointedEars' Lahn wrote:
> Andrew Poulos wrote:
>
>> I have a page laid out like this
>>
>> <!DOCTYPE html>
>> <html>
>> <head>
>> ...
>> <script type="text/javascript" src="scripts/a.js"></script>
>> ...
>> </head>
>> <body>
>> ...
>> <script type="text/javascript">
>>     // b
>> </script>
>> ...
>> </body>
>> </html>
>>
>> "a.js" has a window.onload
>>
>> Interestingly Chrome and Opera run the code at "b" after the onload is
>> triggered but only if the page is on a web server. If the page is on my
>> local file system the code at "b" runs first.
>
> “http://” vs. “file://”?

Yes.

> Which versions?

On Windows Vista SP 2 with Opera 18.0, Chrome 31.0.1650.57 m, and IIS 
7.0.6000.16386.

Andrew Poulos

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


#22192

FromAndrew Poulos <ap_prog@hotmail.com>
Date2013-11-27 11:35 +1100
Message-ID<nvqdnZk-fu41owjPnZ2dnUVZ_qGdnZ2d@westnet.com.au>
In reply to#22191
On 27/11/2013 10:15 AM, Andrew Poulos wrote:
> On 27/11/2013 9:06 AM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>
>>> I have a page laid out like this
>>>
>>> <!DOCTYPE html>
>>> <html>
>>> <head>
>>> ...
>>> <script type="text/javascript" src="scripts/a.js"></script>
>>> ...
>>> </head>
>>> <body>
>>> ...
>>> <script type="text/javascript">
>>>     // b
>>> </script>
>>> ...
>>> </body>
>>> </html>
>>>
>>> "a.js" has a window.onload
>>>
>>> Interestingly Chrome and Opera run the code at "b" after the onload is
>>> triggered but only if the page is on a web server. If the page is on my
>>> local file system the code at "b" runs first.
>>
>> “http://” vs. “file://”?
>
> Yes.
>
>> Which versions?
>
> On Windows Vista SP 2 with Opera 18.0, Chrome 31.0.1650.57 m, and IIS
> 7.0.6000.16386.

I "solved" the issue by moving
   <script type="text/javascript" src="scripts/a.js"></script>
to the bottom of the page.

Andrew Poulos

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


#22193

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-11-27 01:39 +0100
Message-ID<1539881.xPIgsfFhHx@PointedEars.de>
In reply to#22192
Andrew Poulos wrote:

> On 27/11/2013 10:15 AM, Andrew Poulos wrote:
>> On 27/11/2013 9:06 AM, Thomas 'PointedEars' Lahn wrote:
>>> Andrew Poulos wrote:
>>>> I have a page laid out like this
>>>>
>>>> <!DOCTYPE html>
>>>> <html>
>>>> <head>
>>>> ...
>>>> <script type="text/javascript" src="scripts/a.js"></script>
>>>> ...
>>>> </head>
>>>> <body>
>>>> ...
>>>> <script type="text/javascript">
>>>>     // b
>>>> </script>
>>>> ...
>>>> </body>
>>>> </html>
>>>>
>>>> "a.js" has a window.onload
>>>>
>>>> Interestingly Chrome and Opera run the code at "b" after the onload is
>>>> triggered but only if the page is on a web server. If the page is on my
>>>> local file system the code at "b" runs first.
>>>
>>> “http://” vs. “file://”?
>>
>> Yes.
>>
>>> Which versions?
>>
>> On Windows Vista SP 2 with Opera 18.0, Chrome 31.0.1650.57 m, and IIS
>> 7.0.6000.16386.
> 
> I "solved" the issue by moving
>    <script type="text/javascript" src="scripts/a.js"></script>
> to the bottom of the page.

I can only test later, but ISTM there is a race condition which would mean 
that you cannot rely on that.

-- 
PointedEars

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

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


#22194

FromArchenoth <Archenoth@live.something>
Date2013-11-26 22:47 -0600
Message-ID<op.w66x88q8bm00eh@hathor>
In reply to#22188
On Tue, 26 Nov 2013 15:24:09 -0600, Andrew Poulos <ap_prog@hotmail.com>  
wrote:

> I have a page laid out like this
>
> <!DOCTYPE html>
> <html>
> <head>
> ...
> <script type="text/javascript" src="scripts/a.js"></script>
> ...
> </head>
> <body>
> ...
> <script type="text/javascript">
>    // b
> </script>
> ...
> </body>
> </html>
>
> "a.js" has a window.onload
>
> Interestingly Chrome and Opera run the code at "b" after the onload is  
> triggered but only if the page is on a web server. If the page is on my  
> local file system the code at "b" runs first.
>
> Andrew Poulos

script tags are run as they are read, I believe the variation is just a  
matter of file:// (local) reading faster than http:// (downloaded).

window.onload = function(){}; will execute when the entire page is loaded.  
That very well might be enough time for the code in the script tags at "b"  
to run, with a higher likelihood to run first the longer it takes to  
download a.js.

-- 
The arch foe

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


#22195

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2013-11-27 15:18 +0000
Message-ID<d73c99h0v1q9ijomsk3njr7o68u0c9o6b5@4ax.com>
In reply to#22188
On Wed, 27 Nov 2013 08:24:09 +1100, Andrew Poulos
<ap_prog@hotmail.com> wrote:

>I have a page laid out like this
>
><!DOCTYPE html>
><html>
><head>
>...
><script type="text/javascript" src="scripts/a.js"></script>
>...
></head>
><body>
>...
><script type="text/javascript">
>   // b
></script>
>...
></body>
></html>
>
>"a.js" has a window.onload
>
>Interestingly Chrome and Opera run the code at "b" after the onload is 
>triggered but only if the page is on a web server. If the page is on my 
>local file system the code at "b" runs first.

Is it not possible to rearrange the 'b' code into functions that are
called by the onload function? Wouldn't that avoid any reliance on
undocumented, and possibly unknown, features of the various browsers.

  John

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


#22200

FromAndrew Poulos <ap_prog@hotmail.com>
Date2013-11-28 09:44 +1100
Message-ID<TdGdnc44D_WA6wvPnZ2dnUVZ_qadnZ2d@westnet.com.au>
In reply to#22195
On 28/11/2013 2:18 AM, John Harris wrote:
> On Wed, 27 Nov 2013 08:24:09 +1100, Andrew Poulos
> <ap_prog@hotmail.com> wrote:
>
>> I have a page laid out like this
>>
>> <!DOCTYPE html>
>> <html>
>> <head>
>> ...
>> <script type="text/javascript" src="scripts/a.js"></script>
>> ...
>> </head>
>> <body>
>> ...
>> <script type="text/javascript">
>>    // b
>> </script>
>> ...
>> </body>
>> </html>
>>
>> "a.js" has a window.onload
>>
>> Interestingly Chrome and Opera run the code at "b" after the onload is
>> triggered but only if the page is on a web server. If the page is on my
>> local file system the code at "b" runs first.

I thought moving "a" to the end of the page would solve the issue but 
Chrome on Android 4.1.2 is still a problem.

> Is it not possible to rearrange the 'b' code into functions that are
> called by the onload function? Wouldn't that avoid any reliance on
> undocumented, and possibly unknown, features of the various browsers.

What's happening is that there's some "default" content that appears 
right before "b". If javascript is enabled then "b" will hide by setting 
some CSS. When the page loads "a" will update the content with 
new/current content and show it.

The content is being correctly updated but then "b" hides it. Its as 
though Chrome is running referenced script files before it runs inline 
scripts!

Andrew Poulos



[toc] | [prev] | [standalone]


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


csiph-web