---
url: "https://web.dev/articles/speed-html5"
titulek: "Improving the performance of your HTML5 App | Articles | web.dev"
h1: "Improving the performance of your HTML5 App Stay organized with collections Save and categorize content based on your preferences."
popis: ""
jazyk: "en"
kanonicka: "https://web.dev/articles/speed-html5"
drobecky: ["Articles", "Improving the performance of your HTML5 App"]
zdroj: "live"
wayback_snapshot: ""
stazeno: "2026-09-14 03:30:52"
znaku: 26902
slov: 4141
kodovani: "iso-8859-2"
sha256: "befa09ee8400aab7f3df5f5ab07e569fd900673ffecb65474fe3441df7ad3fa1"
---
Improving the performance of your HTML5 App
Stay organized with collections
Save and categorize content based on your preferences.
Malte Ubl
Introduction HTML5 gives us great tools to enhance the visual appearance of web applications. This is especially true in the realm of animations. However, with this new power also come new challenges. Actually these challenges aren't really that new and it might sometimes make sense to ask your friendly desk neighbor, the Flash programmer, how she has overcome similar things in the past. Anyway, when you work in animation it becomes hugely important that users perceive these animations to be smooth. What we need to realize is that smoothness in animations can't really be created by simply increasing the frames per second beyond any cognitive threshold. Our brain is, unfortunately, smarter than that. What you will learn is that true 30 frames of animation per second (fps) is much better than 60 fps with just a few frames dropped in the middle. People hate jaggedness. This article will try to give you the tools and techniques to work on improving the experience of your own application. The Strategy By no means do we want to discourage you from building awesome, stunningly visual apps with HTML5. Then when you notice that performance could be a little better, come back here and read up on how you can improve the elements of your application. It can, of course, help to do some things right in the first place but never let that get in your way of being productive. Visual fidelity++ with HTML5 Hardware Acceleration Hardware acceleration is an important milestone for overall render performance in the browser. The general scheme is to offload tasks that would otherwise be calculated by the main CPU to the graphics processing unit (GPU) in your computer's graphics adapter. This can yield massive performance gains and can also reduce resource consumption on mobile devices. These aspects of your document can be accelerated by the GPU General layout compositing CSS3 transitions CSS3 3D transforms Canvas Drawing WebGL 3D Drawing While acceleration of canvas and WebGL are special purpose features that might not apply to your specific application the first three aspects can help pretty much every app to become faster. What can be accelerated? GPU acceleration works by offloading well-defined and specific tasks to special purpose hardware. The general scheme is that your document is broken down into multiple "layers" which are invariant to the aspects of your page that are accelerated. These layers are rendered using the traditional render pipeline. The GPU is then used to composite the layers onto a single page applying the "effects" that can be accelerated on the fly. A possible outcome is that an object that is animated on the screen does not require a single "relayout" of the page while the animation happens. What you need to take away from that is that you need to make it easy for the rendering engine to identify when it can apply it's GPU acceleration magic.
Consider the following example: While this works, the browser doesn't really know that you are performing something that is supposed to be perceived as smooth animation by a human being. Consider what happens when you achieve the same visual appearance using CSS3 transitions instead: How the browser implements this animation is completely hidden from the developer. This in turn means that the browser is able to apply tricks such as GPU acceleration to achieve the defined goal. There are two useful command-line flags for Chrome to help debugging GPU acceleration: `--show-composited-layer-borders` shows a red border around elements that are
being manipulated at the GPU level. Good for confirming your manipulations occur within the GPU layer. `--show-paint-rects` all non-GPU changes are painted and this throws
a light border around all areas that are repainted. You can see the browser optimizing paint areas in action. Safari has similar runtime flags [described here](http://mir.aculo.us/2011/02/08/visualizing-webkits-hardware-acceleration/). CSS3 Transitions CSS Transitions make style animation trivial for everyone, but they also are a smart performance feature. Because a CSS transition is managed by the browser, the fidelity of its animation can be greatly improved, and in many cases hardware accelerated. Currently WebKit (Chrome, Safari, iOS) have hardware accelerated CSS transforms, but it's coming quickly to other browsers and platforms. You can use [`transitionEnd`](https://developer.mozilla.org/CSS/CSS_transitions) events in order to script this into powerful combinations, though right now, capturing all supported transition end events means watching `webkitTransitionEnd transitionend oTransitionEnd`. Many libraries have now introduced animation APIs that leverage transitions if present and fall back to standard DOM style animation otherwise. [scripty2](http://scripty2.com/), [YUI transition](http://developer.yahoo.com/yui/3/transition/), [jQuery animate enhanced](http://playground.benbarnett.net/jquery-animate-enhanced/). CSS3 Translate I'm sure you've found yourself animating the x/y position of an element across the page before. You probably manipulated the inline style's left and top properties. With 2D transforms, we can use the `translate()` functionality to replicate this behavior. We can combo this with DOM animation to use the best thing possible `
` We use Modernizr to feature test for CSS 2D Transforms and CSS Transitions, if so we're going to use translate to shift the position. If this is animated using a transition there is a good chance the browser can hardware accelerate it. To give the browser another push in the right direction we'll use the "magic CSS bullet" from above. If our browser is less capable, we'll fallback to jQuery to move our element. You can pick up the [jQuery Transform polyfill plugin](http://louisremi.github.io/jquery.transform.js/index.html) by Louis-Remi Babe to make this whole thing automatic. `window.requestAnimationFrame` `requestAnimationFrame` was introduced by Mozilla and iterated on by WebKit with the goal of providing you a native API for running animations, whether they be DOM/CSS-based or on `