I have a web server that updates its data once a minute and wants to make this data available to all types of clients. To reduce throughput, I configured a PHP script to support conditional GET using IF-MODIFIED-SINCE and / or IF-NONE-MATCH. The idea is that customers can poll every 30 seconds and thus be sure that they will not miss anything, but also will not receive duplicate data.
Everything works fine for most types of clients, and I verified that it works with clients that support the standard GET semantics of conditional HTTP.
But it does not work with JavaScript, because JSONP inserts a <script> tag in the DOM and allows the browser to handle things - and there is no support (at least not one that I know) for conditional GETs in <script> tags.
So, I modified my PHP script to support passing the etag value. The returned data contains an etag value unique to this minute. When the JavaScript client receives data from the server, it stores the etag value so that it can use this value in subsequent requests. The request takes the form:
http:
If the data phase does not match the transmitted phase, I send new data.
This all worked well and was surprisingly easy to code using jQuery. My dilemma, although this is what you need to do if matches etag. I see two options:
- Returns HTTP 304 (no change)
- HTTP 200 (OK), , ( , etag ..) .
, JavaScript . , , 304 <script> . ... - . , , , , . , 304.
, , , . , .
, . JavaScript , ? , "" ? "", ( )? ?