473,671 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Browser Requests

how do I know when the browser is making a request to the server? I am
not having an onclick event for EVERY hyperlink, submit, etc. There
must be some javascript function that I can overwrite that will allow
me to do something when the browser requests something from the server.
My plan is whenever a browser is about to request something from the
server to create a time stamp and then compare this time to the time
when the page returns from the server. This will allow me to measure
performance.

Thanks in advance to all that help!

Jul 23 '05 #1
3 2089
"Bond" <ni************ **@gmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
how do I know when the browser is making a request to the server? I
am
not having an onclick event for EVERY hyperlink, submit, etc. There
must be some javascript function that I can overwrite that will allow
me to do something when the browser requests something from the
server.
No.
My plan is whenever a browser is about to request something from the
server to create a time stamp and then compare this time to the time
when the page returns from the server. This will allow me to measure
performance.


Even if you could identify when the browser is making a request to the
server in a generic way and create a timestamp of that instant, the
script holding that timestamp would disappear as soon as a new page
loaded, so there would be no way to compare the current time to the
previously stored timestamp since it would no longer exist.

A better alternative might be to attempt to load an image of a known
size and time it takes to download that. Of course, all you'd be
measuring is the time it takes to download that image at that moment in
time, which may or may not represent the actual bandwidth the end-user
has available.

<script type="text/javascript">
var t = (new Date()).getTime ();
var fileSize = 1234567;
var i = new Image();
i.onload = determineConnec tionSpeed;
i.src = 'path\to\file.j pg?' + (Math.random() * 9e9);
function determineConnec tionSpeed() {
alert(
Math.floor((fil eSize * 8) / ((new Date()).getTime () - t) * 1000)
+
'bps'
)
}
</script>

Of course, there is the question of how accurate this will be. A bigger
file will probably make the test more accurate, but ask yourself whether
your users will appreciate being forced to download a 1MB+ image just so
you can determine their connection speed.

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
Bond wrote:
how do I know when the browser is making a request to the server? I am
not having an onclick event for EVERY hyperlink, submit, etc. There
must be some javascript function that I can overwrite that will allow
me to do something when the browser requests something from the server.
My plan is whenever a browser is about to request something from the
server to create a time stamp and then compare this time to the time
when the page returns from the server. This will allow me to measure
performance.

Thanks in advance to all that help!


I'm not aware of any such function but, with some struggle, you might
be able to finagle something very unreliable that does something
remotely similar.

But I'd venture to say that the statistics you'd end up with are
probably not what you're after. The effect of server-side performance
would be buried deeply behind: performance of the Internet, the
client's Internet connection, the client's geographic location, the
client's browser and possibly other software, and the client's computer
hardware. It would be impossible to extract server performance from the
mix.

If what you want is data about server performance, most web server
software packages provide some mechanism for obtaining this
information, at per-request times or even at high-level statistical
charts and graphs.

For instance, if you're using Apache, it comes with something called
the "Scoreboard ". I've never used it myself, but I understand that it
can give you detailed high-level analysis of server performance. For
per-request data, there's a field somewhere that you can add to the log
that will tell you how long it took from the time the server received
the request to the time the server completed it.

If you really need that outside view, you might consider writing a
script (but not in client-side JS-- PERL, Python, or something) that
runs on another server that will make periodic requests to check
response times, or if you're on a large budget, use a service like
Gomez (gomez.com) that does this for you at various points directly on
various backbones of the Internet.

Jul 23 '05 #3
Bond wrote:
how do I know when the browser is making a request to the server? I am
not having an onclick event for EVERY hyperlink, submit, etc. There
must be some javascript function that I can overwrite that will allow
me to do something when the browser requests something from the server.
My plan is whenever a browser is about to request something from the
server to create a time stamp and then compare this time to the time
when the page returns from the server. This will allow me to measure
performance.

Thanks in advance to all that help!


I presume that you are only using this as a bit of a hack to see how
long pages take to load for test and evaluation purposes and don't
expect the results to be particularly reliable.

The simple (i.e. quick, easy but unreliable) way is to place a button on
the page that, when clicked, updates a cookie with the current timestamp
then reloads a page. An onload function compares the cookie's timestamp
to the current time, displays the difference and clears the cookie.
Clearing the cookie ensures that the time difference is only displayed
if the custom reload button was clicked.

It's not particularly reliable, but it's probably OK for testing.
Caching will likely affect results and network and server latency will
all be bundled in.

A more complex but possibly more useful way is to attach the cookie
setting function to the body onclick event and a check function on the
onunload event. If the onunload is fired less than say 0.5 seconds
after the last click, it is likely that the unload was caused by a click
on a navigation link on your page. Any longer and the user may have
used some other navigation (say bookmark or forward/back buttons) to
cause the unload so clear the cookie. The next time the page loads, no
stats will be recorded.

If you have links on your pages that go to other sites, use the event to
find the link that was clicked on, and if the href is not on your site,
clear the cookie. This further reduces the possibility that you will
include external navigation in your stats, but is by no means perfect.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Page load time </title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<style type="text/css">
#msgBox {
border: 1px solid blue; position: absolute; left: 5ex; top:5ex;
color: blue; background-color: #eeeeff; width: 25em;
padding: 5px 5px 5px 10px; display: none;
}
#msg {
margin:0; padding:0
}
#close {
float: right; text-decoration: underline; font-weight: bold;
padding: 0 15px 0 0; margin-top: -2ex; cursor: pointer;
}
</style>
<script type="text/javascript">

function updateEventCook ie(e){
var e = e || window.event;
var n = new Date();
var t = n.toGMTString() ;
n.setDate( n.getDate()+1 );
document.cookie = 'eStamp=' + t + '&&' + ((e)?e.type:'un known')
+ '; expires=' + n.toGMTString() + '; path=/';
}

// Gets the timestamp from the cookie and compares it
// to the current time
function timeSinceLastEv ent() {
var now = new Date();
if ( ! document.cookie
|| ! document.cookie .match('&&')
) return;
var c = document.cookie ; //.split(';');
var oT = new Date( c.split('=')[1].split('&&')[0] );
var oE = c.split('&&')[1];
msg.innerHTML =
'<b>' + oE + '</b> event at: ' + oT + '<br>'
+ 'This page loaded: ' + now + '<br>'
+ '<b>Δ&nbsp;: ' + padZ( (now - oT)/1000, 3 )
+ '</b>&nbsp;seconds '
;
msgBox.style.di splay='block';
}

function padZ( x, n ){
x += '';
var y = x.split('.');
y[1] = ( y[1] )? '.' + y[1] : '.0';
var i = y[1].length
while ( i++ <= n ) y[1] += '0';
return y[0]+y[1];
}

function clearCookie(e){
var exp = new Date();
exp.setDate( exp.getDate()-1 );
document.cookie = 'eStamp=; ' + 'expires=' + exp + '; ' + 'path=/';
}

</script>
</head>

<body onload="
timeSinceLastEv ent();
clearCookie(eve nt);
">

<input type="button" value="Timed reload" onclick="
updateEventCook ie(event);
window.location .reload( false );
">

<div id="msgBox"><p id="msg"></p><span id="close" onclick="
document.getEle mentById('msgBo x').style.displ ay='none';
">◊&nbsp;Cl ose</span>
</div>

<script type="text/javascript">
// For messages - I hate alerts
var msg = document.getEle mentById('msg') ;
var msgBox = document.getEle mentById('msgBo x');
</script>

</body>
</html>

--
Rob
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1031
by: Mark | last post by:
Hi all, i am trying to create a small app which can record the requests from and responses to my browser. To achieve this i am using two tcpclients and a listener. The first 1 is listening to a port on my localhost to intercept the browsers request. The second 1 uses the stream of tcpclient1 and forwards it to the target. The response-stream from the target is read from tcpclient2 and
25
2894
by: Ryan Stewart | last post by:
I'm working on a project to collect web application usage statistics. What are the recommended ways of detecting whether a browser is JavaScript enabled and/or capable? Obviously I can write a script to invoke something on the server, and if it works, then it works. Is there a better way? I'm looking for the least intrusive way of doing it, from a web application point of view. i.e. I'd like to be able to drop this into an existing...
1
3044
by: John Giblin | last post by:
I was trying to write a program that captures the requests and responses from the browser. I tried using the tcplistener using the acceptsocket method, but realize this was incorrect since I got an error, since I had a web server running. I just want to see the requests and responses from IE, much like web application stress tool, when you are recording a script. First, I wanted to know how IE works with and a webserver running on your...
3
1186
by: Rajiv Das | last post by:
C# 2.0 XP SP2 In My Code, I am using HttpWebRequest to visit a particular URL. I am required to generate a snapshot image (if this request were made through say IE) and save as jpeg. About .1 million such requests are made in a cycle. What's the possible solution ?
3
2025
by: Scott | last post by:
I wish to have a link on a page that launches a new browser before it loads the target link. The standard _new and _blank include the parent browser's cookies. Is there an alternative method that excludes these cookies? Thanks in advance
5
2059
by: jeremy | last post by:
I have an ASP.Net 2.0 application running on Windows Server 2003. The application displays properly in Internet Explorer, however, when I use a browser control embedded in a .net form, I get an error and am directed to the Windows Application Event Log. The following message is logged: ------------- Source: ASP.NET 1.1.4322.0 Event ID: 1062
6
2396
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am thinking about doing this since I got several cases that some of our internal users open more than one browser at the same time from our server. When one of the transactions was not completed finished, the second browser jusk pick up some session variables from the first browser and process right after that. It messed up everything. I was thinking about use remote_addr, but it seems not working since we are behind the...
6
2218
by: ernesto.tejeda | last post by:
Hello, I have a couple of questions regarding the loading of .js files for the browser and would like anyone to point me wher to find the answer (or if you know the answer and tell me will do just fine ;) ) - If I have several pages all using 'somejs.js' file this file is shared on disk and is downloaded only once... but how about in memory, is it also shared and just loaded once? -Also, when are the .js files unloaded from memory?
10
3252
by: Conrad Lender | last post by:
In a recent thread in this group, I said that in some cases object detection and feature tests weren't sufficient in the development of cross-browser applications, and that there were situations where you could improve the application by detecting the browser vendor/version. Some of the posters here disagreed. Since then, I've had to deal with a few of these cases; some of them could be rewritten to use object detection, and some couldn't....
0
8390
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8911
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.