S
S
spmbt2013-02-20 18:30:24
Habr
spmbt, 2013-02-20 18:30:24

Habr's 404 page eats up a lot of CPU resources and the script doesn't turn off?

The script on habrahabr.ru/404/ is written in such a way that it recalculates the coordinates of DOM objects with the maximum speed (1 ms interval) available to the browser. This leads to the fact that loading Firefox on a 2-core e7200, for example, 33%, for Chrome - about 4%, for Opera - 6-8%, is disabled on an inactive tab.

$(document).ready(function(){
  var brainstorage = $('.brainstorage')
  var hantim = $('.hantim')
  var freelansim = $('.freelansim')

  var brainstorage_start = 0;
  var hantim_start = 1600;
  var freelansim_start = 3600;
  
  setInterval(function(){    
    ++brainstorage_start;    
    var brainstorage_css = {
    	'left': Math.sin(brainstorage_start * 0.001) * 165, 
    	'top': Math.cos(brainstorage_start * 0.001) * 165
    	}
    brainstorage.css(brainstorage_css);
   	
   	++hantim_start;    
    var hantim_css = {
    	'left': Math.sin(hantim_start * 0.001) * 160 , 
    	'top': Math.cos(hantim_start * 0.001) * 160
    	}
    hantim.css(hantim_css); 
    
    ++freelansim_start;    
    var freelansim_css = {
    	'left': Math.sin(freelansim_start * 0.001) * 165 , 
    	'top': Math.cos(freelansim_start * 0.001) * 165
    	}
    freelansim.css(freelansim_css); 
  }, 1);
})

Actually, the solution was found, the load immediately drops to the background 1%: but, apparently, this is not what the creators wanted: ); Question : how to add the Habr script so that it works correctly? On other systems, the results will be different, so the second question is who has what loading with the existing script of different browsers and on what systems? Are many people so bad at Fx?
$('.hantim,.freelansim,.brainstorage').remove();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
stampoon, 2013-02-20
@stampoon

Linux, x86, FF 20.0a2, AMD A10-5700, eats 30%

E
egorinsk, 2013-02-21
@egorinsk

The code on the page was clearly assigned to an inexperienced intern.
- It is necessary to use requestAnimationFrame where it is available
- It is necessary to calculate the position of the object from the time and the equation of motion, and not increase it every time by a certain step (since no one guarantees that the callback will be called evenly, in practice this is not the case)
- Canvas can give a win , or maybe not, plus you have to think about what to do in IE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question