Designing web animations for performance and consent
Animated websites need to load quickly and respond promptly to input. Both are easier to test when the content, effects, and analytics scripts can start independently.
Load the content before the effect
Deliver the heading, navigation, and main content in the HTML. Reserve space for project images with explicit dimensions. A decorative grid can start as a static CSS background. Load the canvas module separately so it can start after the layout is in place.
Canvas drawing costs increase at high pixel densities. Test on an actual mobile device to find the resolution your effect needs. Store the latest pointer position and process it in the next animation frame.
Pause in hidden tabs and respect reduced motion
Use visibilitychange to stop the animation loop when the tab becomes hidden. When the tab returns, check that it is visible and reduced motion is disabled before requesting another frame. Respond to changes in the system preference while the page is open.
The media query below stops the decorative CSS effect. A separate canvas animation can check the same preference with matchMedia. The static design stays visible.
@media (prefers-reduced-motion: reduce) {
.ambient-grid {
animation: none;
}
}Test consent in the Network panel
Open a fresh browser profile and start recording network traffic before the first visit. With Basic Consent Mode, Google tags stay blocked before a choice and after rejection. After analytics consent, the configured analytics tag can load.
Test withdrawal too. Clear the network log after withdrawing, then open another page to check for new requests. Compare a first visit without consent with a reload after consent has been saved. Separate traces show which resources and script tasks analytics adds.
Measure loading, stability, and responsiveness
Run a mobile Lighthouse audit to examine the initial load and layout stability. Record a navigation or click while the animation is running in the browser’s performance tools. This helps you find long script tasks and rendering work that compete with input.
When field data is available, assess LCP, INP, and CLS separately for mobile and desktop. Google uses the 75th percentile. Lighthouse runs give you a repeatable comparison as you make changes during development.