When Was It Modified?
The hardest part in getting dynamic web pages cached properly is the computation of the content-modification time. A simplistic approach might look at the modification timestamp of the source .asp, .aspx, or .php file and would be guaranteed to break if the displayed content is based on information outside of the source file—for example, content generated by included libraries or content from a database or external file.
To get a reliable Last-Modified date/time for content primarily contained in the ASP/PHP file (not in a database table, which we’ll cover in part 3 of this series), you’ll need to address these issues:
- The navigational and promotional elements not directly related to the content-modification timestamp should be extracted into separate modules and loaded separately. (I’ve described this process in my article "Improve Your Search Engine Ranking with AJAX.") This step will actually improve the performance of your web site, as the content will be cacheable longer than it would be if it included faster-changing banners or sidebars.
- The content-modification date is the latest timestamp of the current script (ASP/PHP page) and any external files it references.
- If you display the design elements of your web page in a library (for example, a subroutine that includes common elements in the HEAD tag), you should consider the date/time of last significant change to these libraries when computing the Last-Modified header. Alternatively, you might just use the date of the last major design change as the initial value of the Last-Modified header.
A few functions in the CachingLibrary can help you to compute the date/time of the latest content modification:
- The getFileModifiedDate function returns the modified date/time for the specified file. (The input parameter should be the physical path to the actual file.)
- The Max function returns a maximum of two values.
- The getMaximumValue function returns a maximum value in an array.
- The SetLastModified subroutine sets the Last-Modified date/time to the maximum of the current value (stored in the LastModified variable) and the specified date/time.
After you have computed the Last-Modified date/time, call the CheckModifiedDate function in the Caching Library. (The detailed operation is described in the next section.)