davatron5000 / FitText.js

A jQuery plugin for inflating web type
http://fittextjs.com
6.76k stars 1.39k forks source link

Using requestAnimationFrame for improved perfs #62

Closed regiskuckaertz closed 10 years ago

regiskuckaertz commented 11 years ago

Use recent browsers' support for the requestAnimationFrame API will prevent superfluous window repaints and therefore increase the overall performance of the page.

Some background

davatron5000 commented 11 years ago

So I see your logic here and I've thought about this myself, but right now, we only calculate on resize and orientation change. Real world users rarely resize and change their orientation, so to me it makes more sense to bind to resize than it does to requestAnimationFrame. rAF would cause consistent recalculation whereas resize just calcs when that action is being performed.

Thoughts?

regiskuckaertz commented 11 years ago

Hi Dave, well if you take a look at line 56, you'll notice that rAF is only triggered on resize or orientationchange, i.e. nothing changes regarding the frequency of calculations. The only thing that changes is that the calculations will happen only when the browser decides a reflow/repaint is necessary, which supposedly will reduce screen freezes on an otherwise busy web page. I agree with you, the difference might be futile on its own.

davatron5000 commented 10 years ago

Finally got around to taking a look at this in Timeline Inspector and YAY! Huge improvement. Looks like I can't directly merge this in right now, but I'll take a look at getting these improvements in. Thanks.

regiskuckaertz commented 10 years ago

Yeah! You're welcome, glad you could have a look at it.