But you'll be pleasantly surprised to see that they always match - no matter how quickly you try to leave the page. This is because the script keeps running, even if the user has left the page. This is an important point. If the user visits a page that requests 50,000 records from your database, then closes his browser, shuts down his computer and goes home, your server is still patiently sending carefully formatted HTML to his IP address! This is again getting off the point of this article, but to detect if a user is still listening when performing a lot of work on a page you may want to sprinkle some of these around: // is user still waiting for this page?
if ( !Response.IsClientConnected ( ) )
{
// no, so lets quit
Response.Clear ( ); // clear buffer
Response.End ( ); // quit processing
}
|
The code above only helps if you're doing a lot of processing - chances are that even with this code you'll still get the same number of headers and footers viewed! Aaaaaah! This time it's because you're probably using Response.Buffer = true; and the script executes very quickly. The time is really spent sending the HTML down the 28.8k modem the user is using. So, using the above method won't work, but a very similar one will. Move the code that increments the footer counter into a new file, then call it client-side as an image, the same way my counter works. This means that the header gets incremented when the script starts processing, and the footer is incremented when the user has downloaded all the HTML, which is actually what you care about. Part 3: The CountLosses.asp file... |