📜 ⬆️ ⬇️

Load time counter

Colleagues, friends and simply habraklyudi. A week ago, the code for the download counter was posted on Web Optimizator (for more details on measuring page load time, see the articles about load speed analysis and online store overclocking ).

Now everyone (not) highly loaded project can afford to see what the actual download speed of its pages is for end users.

Load Time Web Optimizator
Graph of webo.in users distribution by loading time of this site
')

An example of current statistics and getting the code is organized here.
http://webo.in/my/action/counter/?url=webo.in
So far, everything is in enough test mode (all statistics are collected, but so far it is displayed only in general form). To view you need to register.

What is already there:
1. Data collection :)
2. Displays a graph of the distribution of the number of users by load time
3. Display average load time
4. Display the number of users who loaded the page up to 4 seconds, inclusive (some characteristic parameter for optimization).
5. Ability to set a date range.
6. The ability to display data for individual browsers and families (18 total)

What is planned to add in just a couple of days:
1. Close statistics for an individual site.
2. Slice download time for individual browsers (now in the database of 17 major)
3. Add any slices for the fastest / slowest pages and view statistics for individual pages.

Several thousand hits per day for an average blog / store service will survive without difficulty. If there are interruptions in the processing of statistics (now the logs are pushed into the database every ten minutes) - I will shake the main “heavyweights” :) For the server is not rubber.

What issues are not resolved:
1. What is the most convenient way to display a list of pages by loading time? Page by table with the ability to sort or invented some other more convenient mode for this?
2. If someone has ideas on how to track a user’s re-entry (when static can be taken from the cache) to the same page without setting a cookie , I will be grateful. To drive a cookie to the statistics server is not very desirable.
3. Yes, how to disable Last-Modified in nginx for the image? Headings want to cut to a minimum.

Naturally, any comments are welcome. The code and available functionality can be obtained on the page.
http://webo.in/my/action/counter/

Principle of operation


JavaScript adds an external image from the statistics server with the main parameters to the window.onload event. window.onload only works when the entire page is loaded in the browser. There should be no conflicts with other handlers, the code looks like this (formatted a little to improve understanding, thoughts are more fully described in a note about the organization of statistics counters ):

  var __WEBO_UA = 0;
 var __WEBO_START = new Date ();
 (function () {
	 window [/ * @ cc_on! @ * / 0? 'attachEvent': 'addEventListener'] (/ * @ cc_on 'on' + @ * / 'load',
		 function () {
			 new Image (1,1) .src = "http://s.webo.name/0.gif?" +
			 __WEBO_UA + ";" +
			 ((new Date ()) -__ WEBO_START) + ";" +
			 escape (location.href) + "; 0;" +
			 Math.random ()
		 }, false)
 } ()); 

Naturally, if you want to try on the initial appearance of the page in the browser, you can hang on a slightly earlier event - the combined onDOMReady , but this is already a matter of taste. The current version of the counter does not affect the performance at all (more precisely, the influence is much less than almost all the current Runet counters).

The idea is not new, but I have never seen a publicly available implementation. In general, IMHO, this should be a handy tool for “dot” profiling of the site’s speed - the code can only be installed on one page, for example.

As usual, I am waiting for comments and fresh ideas: an example of output statistics for webo.in

PS I hope that the counter will not put habraeffekt :)

Source: https://habr.com/ru/post/44567/


All Articles