title: How to poll for updates with JSONP?
body: <p>I have a Web server that updates its data once per minute, and want to make that data available to clients of all types.  In order to reduce bandwidth, I set up the PHP script to support conditional GETs, using IF-MODIFIED-SINCE and/or IF-NONE-MATCH.  The idea is that clients can poll every 30 seconds and thereby be sure that they won't miss anything, but also won't get duplicate data.</p>
  
  <p>That all works great for most types of clients, and I've verified that it works with clients that support the standard HTTP conditional GET semantics.</p>
  
  <p>But it doesn't work with JavaScript because JSONP inserts a &lt;script&gt; tag into the DOM and lets the browser handle things--and there's no support (at least, none that I know of) for conditional GETs in &lt;script&gt; tags.</p>
  
  <p>So I modified my PHP script to support passing an etag value.  The returned data contains an etag value that's unique for that minute.  When the JavaScript client receives data from the server, it saves the etag value so it can use that value in subsequent requests.  The request takes the form:</p>
  
  <pre><code>http://api.mydomain.com/script.php?fmt=json&amp;callback=jscallback&amp;etag=ab79bc65e
  </code></pre>
  
  <p>If the etag of the data doesn't match the passed etag, then I send the new data.</p>
  
  <p>This all works well and was surprisingly easy to code up using jQuery.  My dilemma, though is what to do if the etag matches.  I see two choices:</p>
  
  <ol>
  <li>Return an HTTP 304 (Not Modified)</li>
  <li>Return an HTTP 200 (OK), but with the returned data containing just the header information (modified date, etag, etc.) and no actual data items.</li>
  </ol>
  
  <p>If I do the first, then the JavaScript client code is greatly simplified.  The browser seems to work just fine if it gets a 304 response to an injected &lt;script&gt; tag.  But ... something bothers me about this solution.  I don't know what it is, but it seems like I'm depending on behavior that could be browser-specific.  Some browser might decide to report an error if it gets a 304.</p>
  
  <p>Doing the second would require a little bit more work on the server, slightly more bandwidth, and would require the clients to check the data to see if the data was updated.  It's more work for everybody, but it seems cleaner.</p>
  
  <p>So, to my question.  If you were writing a JavaScript client to get this data, which would you prefer?  A silent failure that never calls your "success" callback?  Or a "success" return that has no data (beyond status) in it?  A third option?</p>