Fixing ETag and honoring Last-Modified

After a little bit of work, prompted by koobs, I’ve made the following code changes.

diff -u -b -r1.47 freshports.php
--- include/freshports.php      10 Apr 2013 18:47:23 -0000      1.47
+++ include/freshports.php      24 Apr 2013 14:59:16 -0000
@@ -712,9 +712,6 @@
        $HTML .= '      <td>';
        $HTML .= '<div id="followus"><div class="header">Follow us</div><a href="http://news.freshports.org/">Blog</a><br><a href="https://twitter.com/freshports/">Twitter</a><br><br>';

-    $HTML .= '<div id="time">';
-       $HTML .= FormatTime(Date("j M Y g:i A T"), $LocalTimeAdjustment, "j M Y g:i A T");
-       $HTML .= '</div></div>';
        $HTML .= '</td>';

 }
@@ -1549,9 +1546,6 @@
 <a href="http://feedvalidator.org/check.cgi?url=http://' . $_SERVER['HTTP_HOST'] . '/backend/rss2.0.php" title="Valid RSS is good too">RSS</a>.
 </small>
 <br>' . freshports_copyright() . '
-
-<br>
-<small>This page created in ' . round($Statistics->ElapsedTime(), 3) . ' seconds.</small>
 </td></tr>
 </table>
 </td></tr>
@@ -1978,7 +1972,7 @@
                return; // etag is there but doesn't match
        }

-       if ($if_modified_since && $if_modified_since != $last_modified) {
+       if ($if_modified_since && $if_modified_since != $LastModified) {
                return; // if-modified-since is there but doesn't match
        }

Lines 8-10 added a time value to the top of the page. This was intended to let the user know when they last refreshed this page.

Lines 18-20 let me know how long it took to generate a given page.

Both are gone now. Why? It meant the page content changed ever time you loaded the page, despite the *ACTUAL* data has not changed. This led to REDbot giving warnings etc. So the page content would change but with an If-Modified-Since conditional request, a 304 would be returned (i.e. no change, use your cache).

Line 29 fixes a long standing bug. The code was looking at the wrong variable. As a result, 200 was always being returned, and ‘304 Not Modified’ was never returned.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top