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


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

Which type of network access for this situation?

Started bybit-naughty@hotmail.com
First post2017-04-17 11:53 -0700
Last post2017-04-18 03:29 +0200
Articles 14 — 7 participants

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


Contents

  Which type of network access for this situation? bit-naughty@hotmail.com - 2017-04-17 11:53 -0700
    Re: Which type of network access for this situation? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-18 00:57 +0100
    Re: Which type of network access for this situation? Stefan Weiss <krewecherl@gmail.com> - 2017-04-18 01:57 +0200
      Re: Which type of network access for this situation? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-04-18 02:52 +0200
        Re: Which type of network access for this situation? Stefan Weiss <krewecherl@gmail.com> - 2017-04-18 03:13 +0200
          Re: Which type of network access for this situation? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-04-18 05:40 +0200
          Re: Which type of network access for this situation? bit-naughty@hotmail.com - 2017-04-18 08:22 -0700
            Re: Which type of network access for this situation? bit-naughty@hotmail.com - 2017-04-18 08:28 -0700
            Re: Which type of network access for this situation? Jon Ribbens <jon+usenet@unequivocal.eu> - 2017-04-18 16:08 +0000
              Re: Which type of network access for this situation? bit-naughty@hotmail.com - 2017-04-19 23:44 -0700
                Re: Which type of network access for this situation? Jon Ribbens <jon+usenet@unequivocal.eu> - 2017-04-20 10:15 +0000
                  Re: Which type of network access for this situation? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-20 12:56 +0200
    Re: Which type of network access for this situation? maherrj@googlemail.com - 2017-04-17 17:23 -0700
    Re: Which type of network access for this situation? Stefan Weiss <krewecherl@gmail.com> - 2017-04-18 03:29 +0200

#33030 — Which type of network access for this situation?

Frombit-naughty@hotmail.com
Date2017-04-17 11:53 -0700
SubjectWhich type of network access for this situation?
Message-ID<7e444aec-2938-4da7-9162-54b71bbe7be7@googlegroups.com>
Suppose after a page is loaded, I want to download some stuff (text or HTML) later, or even immediately and display it. But NOT on a button click, more like say, after a timer goes off or something. What type of networking shit do I use for this? Does it call for AJAX, WebSockets or the DataChannel part of the WebRTC API, which I just got to know about? I'm still not really clear about what the exact differences between each of them are....

Thanks.

[toc] | [next] | [standalone]


#33033

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2017-04-18 00:57 +0100
Message-ID<878tmyoae2.fsf@bsb.me.uk>
In reply to#33030
bit-naughty@hotmail.com writes:

> Suppose after a page is loaded, I want to download some stuff (text or
> HTML) later, or even immediately and display it. But NOT on a button
> click, more like say, after a timer goes off or something. What type
> of networking shit do I use for this? Does it call for AJAX,
> WebSockets or the DataChannel part of the WebRTC API, which I just got
> to know about? I'm still not really clear about what the exact
> differences between each of them are....

If the "stuff" (AKA documents) are available via HTPP (and you can
probably arrange that they are), just use XMLHttpRequest.

-- 
Ben.

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


#33034

FromStefan Weiss <krewecherl@gmail.com>
Date2017-04-18 01:57 +0200
Message-ID<od3kp9$mr9$1@news.albasani.net>
In reply to#33030
bit-naughty@hotmail.com wrote:
> Suppose after a page is loaded, I want to download some stuff (text or
> HTML) later, or even immediately and display it. But NOT on a button click,
> more like say, after a timer goes off or something. What type of networking
> shit do I use for this? Does it call for AJAX, WebSockets or the DataChannel
> part of the WebRTC API, which I just got to know about? I'm still not really
> clear about what the exact differences between each of them are....

Use the XMLHttpRequest object.

There's a simple example at the top of this page:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest

To really understand the differences between the "networking shit" you
mentioned, you'll have to read some documentation (or at least skim their
Wikipedia entries, to get a rough overview).

In a nutshell:

* XMLHttpRequest ("AJAX"): HTTP request/response based, easy to use, your
  method of choice unless you have a very good reason to choose something
  else.

* WebSockets: powerful two-way communication method, can be used to
  implement complex interactions between a server and a client. Once
  opened, a socket stays open, allowing the server to send data to the
  client without getting a request. The WebSockets only provide the
  transport, you are responsible for designing the data exchange protocol.

* WebRTC: a new-ish technology optimized for audio/visual data interchange;
  enables peer-to-peer connections. Use this if you want to build your own
  Skype.


- stefan

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


#33036

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-04-18 02:52 +0200
Message-ID<1611458.0Y0JHutS3l@PointedEars.de>
In reply to#33034
Stefan Weiss wrote:

> bit-naughty@hotmail.com wrote:
>> Suppose after a page is loaded, I want to download some stuff (text or
>> HTML) later, or even immediately and display it. But NOT on a button
>> click, more like say, after a timer goes off or something. What type of
>> networking shit do I use for this? Does it call for AJAX, WebSockets or
>> the DataChannel part of the WebRTC API, which I just got to know about?
>> I'm still not really clear about what the exact differences between each
>> of them are....
> 
> Use the XMLHttpRequest object. […]

Not necessarily.  If a resource is to be downloaded to be saved as a file in 
the filesystem in a user-specified location after a “timer goes off”, then a 
simple

  var timer = window.setTimeout(function () {
    window.clearTimeout(timer);

    window.location = "…";
  }, 42);

suffices, where 42 is the number of milliseconds after this call that the 
“timer goes off” (in backwards-compatible code, it should not be less than 
10).  The resource needs to be served with the proper MIME media type; if it 
should be downloaded to be saved as a file, then “application/octet-stream” 
will trigger the browser’s download dialog.

Any suitable set of statements can be used instead of the assignment to 
“window.location”.  For example, if an image resource is to be displayed, 
code to set the “src” property of an “img” element object, optionally create 
the latter and insert the corresponding “img” node into the document tree 
first, can be used.

If one uses window.setTimeout(), one should also handle the case of 
navigating away before the “timer goes off”, so as not to potentially 
execute code that potentielly produces errors because of missing objects:

  window.onunload = function () {
    window.clearTimeout(timer);
  };

It may be useful to establish a timeout registry that clears all registered 
timeouts in that case.

The usual caveats regarding the use of host-provided features apply.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

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


#33037

FromStefan Weiss <krewecherl@gmail.com>
Date2017-04-18 03:13 +0200
Message-ID<od3p79$9i6$1@news.albasani.net>
In reply to#33036
Thomas 'PointedEars' Lahn wrote:
> Stefan Weiss wrote:
>> Use the XMLHttpRequest object. […]
> 
> Not necessarily.  If a resource is to be downloaded to be saved as a file in 
> the filesystem in a user-specified location after a “timer goes off”, then a 
> simple
> 
>   var timer = window.setTimeout(function () {
>     window.clearTimeout(timer);
> 
>     window.location = "…";
>   }, 42);
> 
> suffices [...]

You don't even need JavaScript for that. This is basically the same as
<meta http-equiv="refresh" content="...">, with all the navigation problems
that come with it.

The OP also wrote "download some stuff [...] _and_display_it_", which I
understood to mean "fetch with JS and insert into the current document". If
this interpretation is correct, neither `window.location = ..` nor a meta
refresh will do what he needs.


- stefan

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


#33040

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-04-18 05:40 +0200
Message-ID<1548999.FzFueAZbcE@PointedEars.de>
In reply to#33037
Stefan Weiss wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Stefan Weiss wrote:
>>> Use the XMLHttpRequest object. […]
>> 
>> Not necessarily.  If a resource is to be downloaded to be saved as a file
>> in the filesystem in a user-specified location after a “timer goes off”,
>> then a simple
>> 
>>   var timer = window.setTimeout(function () {
>>     window.clearTimeout(timer);
>> 
>>     window.location = "…";
>>   }, 42);
>> 
>> suffices [...]
> 
> You don't even need JavaScript for that. This is basically the same as
> <meta http-equiv="refresh" content="...">,

No, it is not.  My example should not be misconstrued as standalone.  
Different to that markup feature, you can call window.setTimeout()
*at any time* in the program.  Most importantly, you can call it
*following a specific user action*.

> with all the navigation problems that come with it.

I am aware of that markup feature, and the problems with it (including 
navigation problems) are why I did not mention it.
 
> The OP also wrote "download some stuff [...] _and_display_it_", which I
> understood to mean "fetch with JS and insert into the current document".
> If this interpretation is correct, neither `window.location = ..` nor a
> meta refresh will do what he needs.

If.  You are jumping to conclusions there, too.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

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


#33045

Frombit-naughty@hotmail.com
Date2017-04-18 08:22 -0700
Message-ID<bf172184-d9f1-43a7-a3df-b15a8f46ac1e@googlegroups.com>
In reply to#33037
On Monday, April 17, 2017 at 8:13:17 PM UTC-5, Stefan Weiss wrote:

> The OP also wrote "download some stuff [...] _and_display_it_", which I
> understood to mean "fetch with JS and insert into the current document". If
> this interpretation is correct, neither `window.location = ..` nor a meta
> refresh will do what he needs.


Yes, that IS what I meant. Let me be clearer about the whole thing - suppose there is a "Page 1" full of stuff. It has a "Next Page", i.e page 2 link on it. While the user is *reading* page 1, I want the text for page 2 to download in the background - and then be displayed immediately as soon as "Next Page" is clicked!! Could you give me some pointers as to how to go about this? I do the AJAX call to get the text for Page 2 as soon as Page 1 is downloaded, right? i.e.:

window.onload = blah blah... request.send(arg=2)  ? Something like that?

And then? How do I receive the incoming text and zap it into the DOM tree?

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


#33046

Frombit-naughty@hotmail.com
Date2017-04-18 08:28 -0700
Message-ID<988b946e-006c-4de7-a04a-f87af9b1cef2@googlegroups.com>
In reply to#33045
On Tuesday, April 18, 2017 at 10:22:13 AM UTC-5, bit-n...@hotmail.com wrote:

> And then? How do I receive the incoming text and zap it into the DOM tree?

Sorry - I forgot to add - zap it into the tree *when the "Next Page" link is clicked*!! Where will the incoming text be stored in between the AJAX call to GET it, and the handler for the "Next Page" button which SHOWS it?? If the entire text hasn't come down by the time "Next Page" is clicked  (ie. Page 1 was quite short, with very little on it), then what happens??

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


#33047

FromJon Ribbens <jon+usenet@unequivocal.eu>
Date2017-04-18 16:08 +0000
Message-ID<slrnofcemk.2ms.jon+usenet@sable.unequivocal.eu>
In reply to#33045
On 18th April in the Year of Our Lord 2017, the illustrious
bit-naughty@hotmail.com whose email address is alleged to be
<bit-naughty@hotmail.com> did communicate, write, or otherwise
convey the following missive:
> On Monday, April 17, 2017 at 8:13:17 PM UTC-5, Stefan Weiss wrote:
>> The OP also wrote "download some stuff [...] _and_display_it_", which I
>> understood to mean "fetch with JS and insert into the current document". If
>> this interpretation is correct, neither `window.location = ..` nor a meta
>> refresh will do what he needs.
>
> Yes, that IS what I meant. Let me be clearer about the whole thing -
> suppose there is a "Page 1" full of stuff. It has a "Next Page", i.e
> page 2 link on it. While the user is *reading* page 1, I want the
> text for page 2 to download in the background - and then be
> displayed immediately as soon as "Next Page" is clicked!! Could you
> give me some pointers as to how to go about this? I do the AJAX call
> to get the text for Page 2 as soon as Page 1 is downloaded, right?

Sounds like you don't need JavaScript at all and actually want
prefetch:

    <link rel="prefetch" href="page2.html"> 

https://www.w3.org/TR/resource-hints/

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


#33068

Frombit-naughty@hotmail.com
Date2017-04-19 23:44 -0700
Message-ID<2ba7e6b7-92e2-4721-8642-a4810271bcdc@googlegroups.com>
In reply to#33047
On Tuesday, April 18, 2017 at 11:12:10 AM UTC-5, Jon Ribbens wrote:

> Sounds like you don't need JavaScript at all and actually want
> prefetch:
> 
>     <link rel="prefetch" href="page2.html"> 
> 
> https://www.w3.org/TR/resource-hints/


Do mobile browsers have this facility?

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


#33075

FromJon Ribbens <jon+usenet@unequivocal.eu>
Date2017-04-20 10:15 +0000
Message-ID<slrnofh2ne.2ms.jon+usenet@sable.unequivocal.eu>
In reply to#33068
On 2017-04-20, bit-naughty@hotmail.com <bit-naughty@hotmail.com> wrote:
> On Tuesday, April 18, 2017 at 11:12:10 AM UTC-5, Jon Ribbens wrote:
>> Sounds like you don't need JavaScript at all and actually want
>> prefetch:
>> 
>>     <link rel="prefetch" href="page2.html"> 
>> 
>> https://www.w3.org/TR/resource-hints/
>
> Do mobile browsers have this facility?

http://caniuse.com/#search=prefetch

TL;DR: Android yes, iOS no.

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


#33076

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-04-20 12:56 +0200
Message-ID<XnsA75D83ADFD6C4eejj99@194.109.6.166>
In reply to#33075
Jon Ribbens <jon+usenet@unequivocal.eu> wrote on 20 Apr 2017 in 
comp.lang.javascript:

> On 2017-04-20, bit-naughty@hotmail.com <bit-naughty@hotmail.com> wrote:
>> On Tuesday, April 18, 2017 at 11:12:10 AM UTC-5, Jon Ribbens wrote:
>>> Sounds like you don't need JavaScript at all and actually want
>>> prefetch:
>>> 
>>>     <link rel="prefetch" href="page2.html"> 
>>> 
>>> https://www.w3.org/TR/resource-hints/
>>
>> Do mobile browsers have this facility?
> 
> http://caniuse.com/#search=prefetch
> 
> TL;DR: Android yes, iOS no.

Different forms of "prebrowsing" are in all stages of developement, 
it seems:

<https://css-tricks.com/prefetching-preloading-prebrowsing/>

<https://medium.com/@luisvieira_gmr/html5-prefetch-1e54f6dda15d>

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

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


#33035

Frommaherrj@googlemail.com
Date2017-04-17 17:23 -0700
Message-ID<543b839a-2350-4764-9dd0-039fb3025ef0@googlegroups.com>
In reply to#33030
On Tuesday, April 18, 2017 at 2:53:30 AM UTC+8, bit-n...@hotmail.com wrote:
> Suppose after a page is loaded, I want to download some stuff (text or HTML) later, or even immediately and display it. But NOT on a button click, more like say, after a timer goes off or something. What type of networking shit do I use for this? Does it call for AJAX, WebSockets or the DataChannel part of the WebRTC API, which I just got to know about? I'm still not really clear about what the exact differences between each of them are....
> 
> Thanks.

There is currently an effort underway to encourage developers to use Fetch in place of XHR

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


#33038

FromStefan Weiss <krewecherl@gmail.com>
Date2017-04-18 03:29 +0200
Message-ID<od3q5n$99f$1@news.albasani.net>
In reply to#33030
bit-naughty@hotmail.com wrote:
> Suppose after a page is loaded, I want to download some stuff (text or
> HTML) later, or even immediately and display it.

There is another very low-effort technique that maybe deserves a mention:
use an iframe. Just set its "src" attribute to the URL for the document you
want to insert (it should be a complete HTML document though, not just a
fragment).
Iframes have some potential drawbacks, too. For example, the iframe content
doesn't inherit stylesheets from the parent, and it may not integrate into
the flow of the page easily. But in certain situations, it may just be the
ticket.


- stefan

[toc] | [prev] | [standalone]


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


csiph-web