<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Smart Polling</title>
	<atom:link href="http://925html.com/code/smart-polling/feed/" rel="self" type="application/rss+xml" />
	<link>http://925html.com/code/smart-polling/</link>
	<description>For those of us who work with the web daily.</description>
	<lastBuildDate>Sun, 14 Mar 2010 18:02:19 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Eric Ferraiuolo</title>
		<link>http://925html.com/code/smart-polling/comment-page-1/#comment-624</link>
		<dc:creator>Eric Ferraiuolo</dc:creator>
		<pubDate>Sat, 31 Oct 2009 07:28:55 +0000</pubDate>
		<guid isPermaLink="false">http://925html.com/?p=288#comment-624</guid>
		<description>@EJ I have since over the months reduced the features of this utility, and the newest code is up on GitHub: http://github.com/ericf/yui3-gallery/tree/master/build/gallery-io-poller/

&lt;a href=&quot;#comment-91&quot; rel=&quot;nofollow&quot;&gt;My comment above&lt;/a&gt; explains the reason for using the Last-Modified date and Etag headers and making Conditional GET requests.

There&#039;s a fundamental difference in your approach using Max-Age, and my approach using Conditional GET requests. I &lt;em&gt;want&lt;/em&gt; to check if there&#039;s a change on the server and know when that change happens ASAP. I have no way to know when the change is going to happen on the server, therefore have no way to accurately set the Max-Age header.

I see what you&#039;re saying about the modern browsers respecting Max-Age and evicting their cached XHR-requested resource representations; this is the exact problem I had, browsers are good at caching the responses of XHR requests.

My question for you is: How do you know what to set the Max-Age response header to? How can you predict when something like a sports score will change?

I want to &lt;em&gt;be in control&lt;/em&gt; of how the browsers are caching all resource representations on my applications (static UI files, XHR-requested resources, etc.); this was the motivating factor behind sending over Conditional GET requests on each XHR-poll of a resource. The server should be quick at determining if what the client has cached is stale or not by comparing an Etag; saving the hit of generating the entity body and sending the payload over the wire by simply responding with a 304 Not Modified response.</description>
		<content:encoded><![CDATA[<p>@EJ I have since over the months reduced the features of this utility, and the newest code is up on GitHub: <a href="http://github.com/ericf/yui3-gallery/tree/master/build/gallery-io-poller/" rel="nofollow">http://github.com/ericf/yui3-gallery/tree/master/build/gallery-io-poller/</a></p>
<p><a href="#comment-91" rel="nofollow">My comment above</a> explains the reason for using the Last-Modified date and Etag headers and making Conditional GET requests.</p>
<p>There&#8217;s a fundamental difference in your approach using Max-Age, and my approach using Conditional GET requests. I <em>want</em> to check if there&#8217;s a change on the server and know when that change happens ASAP. I have no way to know when the change is going to happen on the server, therefore have no way to accurately set the Max-Age header.</p>
<p>I see what you&#8217;re saying about the modern browsers respecting Max-Age and evicting their cached XHR-requested resource representations; this is the exact problem I had, browsers are good at caching the responses of XHR requests.</p>
<p>My question for you is: How do you know what to set the Max-Age response header to? How can you predict when something like a sports score will change?</p>
<p>I want to <em>be in control</em> of how the browsers are caching all resource representations on my applications (static UI files, XHR-requested resources, etc.); this was the motivating factor behind sending over Conditional GET requests on each XHR-poll of a resource. The server should be quick at determining if what the client has cached is stale or not by comparing an Etag; saving the hit of generating the entity body and sending the payload over the wire by simply responding with a 304 Not Modified response.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: EJ</title>
		<link>http://925html.com/code/smart-polling/comment-page-1/#comment-623</link>
		<dc:creator>EJ</dc:creator>
		<pubDate>Sat, 31 Oct 2009 07:11:12 +0000</pubDate>
		<guid isPermaLink="false">http://925html.com/?p=288#comment-623</guid>
		<description>And I also agree that it&#039;s great to promote this standards based way of refreshing content on the page. E-tags and conditional gets are quite powerful and can solve many use cases with off the shelf software.</description>
		<content:encoded><![CDATA[<p>And I also agree that it&#8217;s great to promote this standards based way of refreshing content on the page. E-tags and conditional gets are quite powerful and can solve many use cases with off the shelf software.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: EJ</title>
		<link>http://925html.com/code/smart-polling/comment-page-1/#comment-622</link>
		<dc:creator>EJ</dc:creator>
		<pubDate>Sat, 31 Oct 2009 06:33:52 +0000</pubDate>
		<guid isPermaLink="false">http://925html.com/?p=288#comment-622</guid>
		<description>At sports.yahoo.com, we let the browser do conditional gets and with a proper Max-Age header emitted by the server, all modern browsers properly make the request at the frequency we specify.

IE 6 has some gotcha&#039;s so we&#039;re planning on using a random variable to bust through caches on that browser, but everywhere else, just relying on the browser to do the right thing has worked well. 

See implementation here (when games are going on):
  http://rivals.yahoo.com/ncaa/football/scoreboard

So I question the need for this library.

JS here: http://l.yimg.com/j/static/versioned_asset/v7/js/editorial/js/scorestream.js</description>
		<content:encoded><![CDATA[<p>At sports.yahoo.com, we let the browser do conditional gets and with a proper Max-Age header emitted by the server, all modern browsers properly make the request at the frequency we specify.</p>
<p>IE 6 has some gotcha&#8217;s so we&#8217;re planning on using a random variable to bust through caches on that browser, but everywhere else, just relying on the browser to do the right thing has worked well. </p>
<p>See implementation here (when games are going on):<br />
  <a href="http://rivals.yahoo.com/ncaa/football/scoreboard" rel="nofollow">http://rivals.yahoo.com/ncaa/football/scoreboard</a></p>
<p>So I question the need for this library.</p>
<p>JS here: <a href="http://l.yimg.com/j/static/versioned_asset/v7/js/editorial/js/scorestream.js" rel="nofollow">http://l.yimg.com/j/static/versioned_asset/v7/js/editorial/js/scorestream.js</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: orip</title>
		<link>http://925html.com/code/smart-polling/comment-page-1/#comment-603</link>
		<dc:creator>orip</dc:creator>
		<pubDate>Mon, 24 Aug 2009 15:49:38 +0000</pubDate>
		<guid isPermaLink="false">http://925html.com/?p=288#comment-603</guid>
		<description>Your concept is awesome, thanks! It&#039;s given me inspiration for a polling JS component I&#039;m making.</description>
		<content:encoded><![CDATA[<p>Your concept is awesome, thanks! It&#8217;s given me inspiration for a polling JS component I&#8217;m making.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Ferraiuolo</title>
		<link>http://925html.com/code/smart-polling/comment-page-1/#comment-577</link>
		<dc:creator>Eric Ferraiuolo</dc:creator>
		<pubDate>Mon, 29 Jun 2009 19:24:28 +0000</pubDate>
		<guid isPermaLink="false">http://925html.com/?p=288#comment-577</guid>
		<description>@Andy, I&#039;m not a PHP guy; so I&#039;m unsure about your code you posted. May I ask what your goals are here; high-level what are you hoping to accomplish?</description>
		<content:encoded><![CDATA[<p>@Andy, I&#8217;m not a PHP guy; so I&#8217;m unsure about your code you posted. May I ask what your goals are here; high-level what are you hoping to accomplish?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy D</title>
		<link>http://925html.com/code/smart-polling/comment-page-1/#comment-576</link>
		<dc:creator>Andy D</dc:creator>
		<pubDate>Mon, 29 Jun 2009 19:17:18 +0000</pubDate>
		<guid isPermaLink="false">http://925html.com/?p=288#comment-576</guid>
		<description>Hmm, so I haven&#039;t used Etag values before, but I tried to set it with the PHP header method:

&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;include(&quot;include/database.php&quot;);

$q = &quot;Select * From qryLatestPost&quot;;
$result = $database-&gt;query($q);
$num_rows = mssql_num_rows($result);
	
if($num_rows &gt; 0){
	$DatePosted = mssql_result($result,0,&quot;DatePosted&quot;);
	$DisplayName = mssql_result($result,0,&quot;DisplayName&quot;);
	$PageText = mssql_result($result,0,&quot;PageText&quot;);
	$PageText = addslashes($PageText);
	
	// create ETAG (hash of feed)
	// (HTTP_IF_NONE_MATCH has quotes around it)
	$eTag = md5($DisplayName.$DatePosted);
	header(&#039;Etag: &#039;.$eTag);
	   
	$text = &quot;{ \&quot;label\&quot;:\&quot;$DisplayName\&quot;, \&quot;time\&quot;:\&quot;$DatePosted\&quot; }&quot;;

	// compare Etag to what we got
	if ($eTag == $_SESSION[&quot;HTTP_IF_NONE_MATCH&quot;]) {   
		header(&quot;HTTP/1.0 304 Not Modified&quot;);
		header(&#039;Content-Length: 0&#039;);
	} else {
	// dump feed
		echo $text;
	}
	$_SESSION[&quot;HTTP_IF_NONE_MATCH&quot;] = $eTag;
}&lt;/code&gt;&lt;/pre&gt;

It is technically a dynamic source, but if there hasn&#039;t been a new post, it doesn&#039;t need to update every 5 seconds.

If there is a better way to do this, I&#039;d love to hear about it, otherwise I&#039;ll just keep researching Etags.</description>
		<content:encoded><![CDATA[<p>Hmm, so I haven&#8217;t used Etag values before, but I tried to set it with the PHP header method:</p>
<pre><code class="php">include("include/database.php");

$q = "Select * From qryLatestPost";
$result = $database-&gt;query($q);
$num_rows = mssql_num_rows($result);

if($num_rows &gt; 0){
	$DatePosted = mssql_result($result,0,"DatePosted");
	$DisplayName = mssql_result($result,0,"DisplayName");
	$PageText = mssql_result($result,0,"PageText");
	$PageText = addslashes($PageText);

	// create ETAG (hash of feed)
	// (HTTP_IF_NONE_MATCH has quotes around it)
	$eTag = md5($DisplayName.$DatePosted);
	header('Etag: '.$eTag);

	$text = "{ \"label\":\"$DisplayName\", \"time\":\"$DatePosted\" }";

	// compare Etag to what we got
	if ($eTag == $_SESSION["HTTP_IF_NONE_MATCH"]) {
		header("HTTP/1.0 304 Not Modified");
		header('Content-Length: 0');
	} else {
	// dump feed
		echo $text;
	}
	$_SESSION["HTTP_IF_NONE_MATCH"] = $eTag;
}</code></pre>
<p>It is technically a dynamic source, but if there hasn&#8217;t been a new post, it doesn&#8217;t need to update every 5 seconds.</p>
<p>If there is a better way to do this, I&#8217;d love to hear about it, otherwise I&#8217;ll just keep researching Etags.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Ferraiuolo</title>
		<link>http://925html.com/code/smart-polling/comment-page-1/#comment-574</link>
		<dc:creator>Eric Ferraiuolo</dc:creator>
		<pubDate>Fri, 26 Jun 2009 21:20:43 +0000</pubDate>
		<guid isPermaLink="false">http://925html.com/?p=288#comment-574</guid>
		<description>@Andy The code will preform conditional GET requests to the resource via: If-None-Match (if it has a cached Etag vale) or If-Modified-Since (if it has a cached LastModified date), in that order; Etag takes priority over LastModified. In the case where responses from the resource do not provide either a LastModified or Etag, the code will assume it&#039;s changed, firing the Modified event (useful for polling dynamic resources).</description>
		<content:encoded><![CDATA[<p>@Andy The code will preform conditional GET requests to the resource via: If-None-Match (if it has a cached Etag vale) or If-Modified-Since (if it has a cached LastModified date), in that order; Etag takes priority over LastModified. In the case where responses from the resource do not provide either a LastModified or Etag, the code will assume it&#8217;s changed, firing the Modified event (useful for polling dynamic resources).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy D</title>
		<link>http://925html.com/code/smart-polling/comment-page-1/#comment-573</link>
		<dc:creator>Andy D</dc:creator>
		<pubDate>Fri, 26 Jun 2009 21:08:42 +0000</pubDate>
		<guid isPermaLink="false">http://925html.com/?p=288#comment-573</guid>
		<description>well, never mind, for some reason the data.json file wasn&#039;t uploading using dreamweaver.

I logged into the server and changed it with notepad manually and it did update.

Now I just have to make it read something besides timestamp.

Thanks for the cool API</description>
		<content:encoded><![CDATA[<p>well, never mind, for some reason the data.json file wasn&#8217;t uploading using dreamweaver.</p>
<p>I logged into the server and changed it with notepad manually and it did update.</p>
<p>Now I just have to make it read something besides timestamp.</p>
<p>Thanks for the cool API</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy D</title>
		<link>http://925html.com/code/smart-polling/comment-page-1/#comment-572</link>
		<dc:creator>Andy D</dc:creator>
		<pubDate>Fri, 26 Jun 2009 20:52:25 +0000</pubDate>
		<guid isPermaLink="false">http://925html.com/?p=288#comment-572</guid>
		<description>I&#039;m trying to get this working, and the polling seems to be doing what it&#039;s supposed to, but I haven&#039;t been able to make it detect that a change has been made.

The data.php file isn&#039;t downloadable (comes down as a blank page), so I&#039;ve been simply changing the timestamp in the data.json file by hand. however, it doesn&#039;t seem to be noticing that the file has been updated.

So either it checks something other than the timestamp, or I&#039;m completely missing something important by not seeing the php file.

Would you mind posting the contents for ajax newbies like me?</description>
		<content:encoded><![CDATA[<p>I&#8217;m trying to get this working, and the polling seems to be doing what it&#8217;s supposed to, but I haven&#8217;t been able to make it detect that a change has been made.</p>
<p>The data.php file isn&#8217;t downloadable (comes down as a blank page), so I&#8217;ve been simply changing the timestamp in the data.json file by hand. however, it doesn&#8217;t seem to be noticing that the file has been updated.</p>
<p>So either it checks something other than the timestamp, or I&#8217;m completely missing something important by not seeing the php file.</p>
<p>Would you mind posting the contents for ajax newbies like me?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Ferraiuolo</title>
		<link>http://925html.com/code/smart-polling/comment-page-1/#comment-97</link>
		<dc:creator>Eric Ferraiuolo</dc:creator>
		<pubDate>Mon, 06 Apr 2009 18:23:03 +0000</pubDate>
		<guid isPermaLink="false">http://925html.com/?p=288#comment-97</guid>
		<description>&lt;strong&gt;@Dan&lt;/strong&gt; I like your thinking here. This would effectively allow the server to tell the client when to ping back to see if there has been an update to the resource. I&#039;m unsure how common this type of behavior would be used by either the client developer to let the sever tell what to do, or by a server developer to have an accurate prediction of when &lt;em&gt;dynamic&lt;/em&gt; data would change. It seems, in practice, that max-age Cache-Control values are on the magnitude of hours or greater. That being said, I feel your suggestion falls into the &lt;em&gt;smart&lt;/em&gt; category here; effectively making the component know how to listen to the server in yet another way. I&#039;ve started looking into how to implement this functionality and will try to include it in the next rendition of this component. My caution is to make sure it&#039;s clear to the client API that checking of the max-age Cache-Control value might be going on in the background if no &lt;code&gt;interval&lt;/code&gt; configuration value is set. Currently it is clear to the client that if they don&#039;t set an &lt;code&gt;interval&lt;/code&gt; value that 10,000ms (10 seconds) will be used.

&lt;strong&gt;@Chris&lt;/strong&gt; thanks for the heads-up, fixed the typo.</description>
		<content:encoded><![CDATA[<p><strong>@Dan</strong> I like your thinking here. This would effectively allow the server to tell the client when to ping back to see if there has been an update to the resource. I&#8217;m unsure how common this type of behavior would be used by either the client developer to let the sever tell what to do, or by a server developer to have an accurate prediction of when <em>dynamic</em> data would change. It seems, in practice, that max-age Cache-Control values are on the magnitude of hours or greater. That being said, I feel your suggestion falls into the <em>smart</em> category here; effectively making the component know how to listen to the server in yet another way. I&#8217;ve started looking into how to implement this functionality and will try to include it in the next rendition of this component. My caution is to make sure it&#8217;s clear to the client API that checking of the max-age Cache-Control value might be going on in the background if no <code>interval</code> configuration value is set. Currently it is clear to the client that if they don&#8217;t set an <code>interval</code> value that 10,000ms (10 seconds) will be used.</p>
<p><strong>@Chris</strong> thanks for the heads-up, fixed the typo.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
