Page 1 of 2

JS timeout ...

Posted: Wed Mar 16, 2005 4:01 pm
by jmueller0823
We display newsfeeds via JS from an outside source.

Sometimes those feeds are delayed or unavailable and that delays the page load time.

(The host tells me they have a built in time-out, but we still experience these issues.)

So... is there a way to install our own "time-out" code?
The JS looks like this:

Code: Select all

<script src=&quote;http://headlines.site.org/headlines/feed.js&quote;></script>
We have a php site.

Thanks.

Posted: Wed Mar 16, 2005 4:28 pm
by feyd
hmm options I see
  • could potentially use XMLHTTP objects to request the remote code via the browser for execution through eval()
  • Place the <script> tag where it can be overwritten after a specific in-page timeout is reached.. you should be able to check to see if something it defines exists at intervals to determine if the data is loading..
  • could use a local php script that makes a periodic request for the page on behalf of your server, storing the results in a database or local file. Thus allowing you to pass to your users a cached version of their last response.

Posted: Fri Mar 18, 2005 11:43 am
by infolock
jmueller0823 wrote:We have several newsfeed headlines displayed on our homepage.
Each headline displays via a line of code like this:

Code: Select all

<a href=&quote;http://headlines.site.org/users/mysite/link.asp&quote;>
<script src=&quote;http://headlines.site.org/headlines/headline2.js&quote;></script>
Problem
Sometimes the feeds are slow and affect the load time of our page (sometimes the page will hang for minutes).

The solution I envisioned was to take a daily 'snapshot' of a successful feed (wget?) and then display the headlines as static.

That won't work because wget copies the actual js code.

So, what I'm thinking now is this:

1] Display the js files,
2] extract their text links, and
3] use a different method to place it on the page

Perhaps an intermediate step is to write the links to a text file.

Trying to keep this simple... but...

Ideas? Comments?

The obvious fix would be for the newsfeed host to provide a reliable feed. They tell me they have a timeout built in, but I don't see it...

Thanks.

Posted: Fri Mar 18, 2005 11:44 am
by infolock
anjanesh wrote:
If this is affecting your page then what you can do is have a onload function in the body tag:

Code: Select all

<script type=&quote;javascript/text&quote;>
function showHeadLines()
 {
 	document.write('<scr'+'ipt src=&quote;http://headlines.site.org/headlines/headline2.js&quote;></scr'+'ipt>');
 }
<script>
.
.
<body onload=&quote;showHeadLines()&quote;>
.
.
.
</body>
.
.

Posted: Fri Mar 18, 2005 1:49 pm
by jmueller0823
anjanesh
Tell me more... Makes since, but I think were missing something.... I would expect that showHeadLines() needs to be positioned down in the body where it needs to display the headline...

feyd
could use a local php script that makes a periodic request for the page on behalf of your server, storing the results in a database or local file. Thus allowing you to pass to your users a cached version of their last response.
This is what I was thinking.

Is there a 'canned' solution to this? Tell me more.

Thanks guys.

Posted: Fri Mar 18, 2005 2:36 pm
by anjanesh
Try keeping <script></script> within <head></head> tags - esp when there are functions. It wont make a difference if the showHeadLines() is at the bottom of body. It'll be executed only when the entire body (page) is loaded.
And your JS line <script src="http://headlines.site.org/headlines/feed.js"></script> will written by Javascript when you call it any time <script type="text/javascript">showHeadLines()</script>

Posted: Fri Mar 18, 2005 4:00 pm
by jmueller0823
Anjanesh
I'm sure it's me, I'm having trouble seeing the full picture. Please bear with me.

I think you're proposing something like this:

Code: Select all

<html>
<head>

<script type=&quote;javascript/text&quote;>
function showHeadLines() 
{ 	document.write('<scr'+'ipt src=&quote;http://headlines.site.org/headlines/headline2.js&quote;></scr'+'ipt>'); }
<script>..


</head>

<body onload=&quote;showHeadLines()&quote;>



<table width=&quote;147&quote; border=&quote;0&quote; cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
  <tr> 
    <td width=&quote;147&quote; class=&quote;xsmall&quote;> 
  // SHOW HEADLINE HERE
     </td>
  </tr>
</table>


</body>
</html>
I need the headline displayed on Line 19.
I understand how we're loading the js code after the page load... But I don't see how we actually display the headline (in the table).

Please clarify. Thanks!

Posted: Fri Mar 18, 2005 9:32 pm
by anjanesh
Oh. Try this instead. BTW, in your code above, line 7 should be </script> and line 4 should be <script type="text/javascript">

Code: Select all

<html>
<head>
<script type=&quote;text/javascript&quote;>
function showHeadLines()
 {
 	document.getElementById(&quote;HeadLineCell&quote;).innerHTML = '<scr'+'ipt src=&quote;http://headlines.site.org/headlines/headline2.js&quote;></scr'+'ipt>';

 }
</script>
</head>

<body onload=&quote;showHeadLines()&quote;>

<table width=&quote;147&quote; border=&quote;0&quote; cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
  <tr>
    <td width=&quote;147&quote; class=&quote;xsmall&quote; id=&quote;HeadLineCell&quote;>
    </td>
  </tr>
</table>
 
</body>
</html>

Posted: Fri Mar 18, 2005 11:21 pm
by jmueller0823
anjanesh
Thank you. I'll give it a try.

BTW in the function, you write scr'+'ipt

I've never seen that before (?)

Posted: Fri Mar 18, 2005 11:36 pm
by feyd
you must if you want Javascript to write javascript, otherwise the handler will read your text as Javascript itself, not a string you want to write.

Posted: Sat Mar 19, 2005 12:19 am
by anjanesh
I guess you're not able to get it to work.
Changing the value of innerHTML to <script></script> is not getting the script to load. Dont know why. I thought it would. But document.write() will do the job though.

Posted: Sat Mar 19, 2005 9:11 am
by jmueller0823
anjanesh
Changing the value of innerHTML to <script></script> is not getting the script to load. Dont know why. I thought it would. But document.write() will do the job though.
So, I should replace innerHTML with document.write() ?
you must if you want Javascript to write javascript, otherwise the handler will read your text as Javascript itself, not a string you want to write.
feyd, thank you for the clarification.

Posted: Sat Mar 19, 2005 9:48 am
by anjanesh
But it wont place the news in that cell - it'll write to the last.

Posted: Sat Mar 19, 2005 10:06 am
by jmueller0823
anjanesh
You've lost me...

Posted: Sat Mar 19, 2005 10:20 am
by anjanesh
The onload function will perform when the page has finished loading.
A document.write() will write (append to html code) at last.
But you wanted it in between <td></td> somewhere in the middle. For that I thought changing innerHTML to <script></script> will work but its not. The innerHTML is defintely changed - try changing the value of innerHTML to <b>hello</b> and it'll show hello in bold. But scripts dont seem to be running.