How to Optimize the Performance of a Creative Website
Intro
Optimizing is just letting your code slack off wherever it can
Creative websites usually come with a lot of flashy effects and transitions. Tech keeps getting better and most phones and computers keep getting faster, but you still have to account for all kinds of situations, like someone visiting on an older device. That's where performance optimization becomes essential.
This post starts with how to locate the problem, then breaks optimization down from a big-picture, architectural angle, and ends with an example I ran into myself.
Define the Problem Before You Solve It
Find the right problem
To solve a problem, you first have to define it. You find performance leaks by measuring.
Start by guessing or reasoning about why a page might stutter, which section stutters, which browser, which device, even which action triggers it. Once you've got candidate causes, write a probe to check whether that's really the problem, like hiding a suspected culprit to see if performance jumps.
Don't skip this step, because your visual intuition fools you easily. My own story later is a perfect example, where the problem I guessed and the culprit I measured turned out to be completely different.
Make sure the problem reproduces reliably
Here's one more reminder that has nothing to do with code but matters just as much: sometimes the problem isn't your code, it's your environment.
The measuring tool itself, or other programs running in the background, can manufacture a stutter that looks completely convincing but doesn't really exist. So before you start, make sure the same action reproduces the same problem reliably.
Where to Optimize
To optimize a website and find the right problem, you first need to understand how it's built, so you can treat the right problem. A site usually has two big architectures: DOM/CSS and WebGL/shaders. Each one breaks down into three sub-items, which are three places you can let your code slack off.
DOM / CSS
DOM/CSS rendering is the pixel assembly line the CPU runs through: JS → Style → Layout → Paint → Composite. The CPU works through this in order, and each stage depends on the ones before it.
DOM/CSS cost ≈ which stage you trigger × how many times per frame × how wide the blast radius is.
The further down the chain, the cheaper
Because the CPU runs the whole chain top to bottom, when an animation or interaction changes a property, the later that property sits in the chain, the cheaper it is. For example: transform / opacity only touch the Composite stage; changing background reaches back to the Paint stage; changing width / top / position goes all the way back to the Layout stage.
So it helps to know which CSS property triggers which stage (csstriggers). Anything you can animate with transform/opacity (Composite only), don't do with width/top (which triggers Layout).
Do each thing once per frame
Doing the same thing many times in one frame is pure waste. The classic trap is layout thrashing: you write a new position, then read a position, then write again, forcing the browser to recompute layout several times within a single frame.
A good habit is to measure once, cache it, and only read the cache each frame. For instance, instead of recomputing the scene on every single scroll event, use rAF so scrolling triggers at most one computation per frame.
Keep the blast radius small
If the point above was about the depth of the CPU chain, this one is about breadth, meaning how many elements a single change touches. For example, if an interaction toggles a class on the top of a big section, the whole subtree has to recompute its style.
So only change what truly needs to change, keep the scope as tight as possible, and target styles on the most specific class you can.
WebGL / Shaders
If the CPU rendering DOM/CSS is like one smart worker doing a complex job well, one step at a time, then the GPU handling WebGL/shaders is like a factory with thousands of simpler workers all clocking in at once. Each worker computes the color of one pixel, and the instruction sheet in their hands is called a shader. The same sheet goes out to every worker, and each one applies it to their own pixel. GPU performance comes down to how many pixels that sheet covers, how much work each pixel does, and how many times the same patch of screen gets repainted.
WebGL/shader cost ≈ pixels to color × work per pixel × how many times you repaint the same area.
Fullscreen and Retina are the big pixel spenders
The more pixels an effect covers, the more times the shader runs, which means the same page can perform differently just based on window size. Retina screens are an even bigger spender, because Retina doubles the pixels on each side, so it uses about four times as many pixels total as a regular screen.
So when you optimize, avoid going fullscreen if you don't have to, and the smaller the area an effect covers, the more you save.
Still, "pixel count" has more than one knob to turn. Resolution, coverage, and scale all pull on each other, and the result differs across screens of different densities. I once went around in circles in exactly this pit for a long time, and I wrote about it in Does a Better Screen Give Your Website More Flaws?.
The instruction sheet for each pixel
If the program each pixel runs has lots of loops, many texture samples, or heavy math (like a noise function), all of that cost gets multiplied by the pixel count.
So keep the shader simple, sample less, and bake results into a texture ahead of time when you can, so you're not recomputing every frame. The simpler it is, the better it runs.
How many times the same area is repainted
Complex effects often aren't drawn in one go, they're stacked up in layers. Take the crystal in the clip below. It looks like it's drawn in a single pass, but there are actually several behind the scenes: first the tunnel grid in the background, then the crystal drawn onto a temporary image, then a fluid simulation, and finally one last pass that composites the crystal and the fluid together and writes them to the screen.
The way to optimize here is to merge layers wherever you can, so the effect shows up with the fewest draws possible.
These two tracks aren't split by how you write them
I split things into two tracks earlier to make them easier to understand, but what actually decides which track runs isn't the syntax you write, it's who really does the computing. Frosted glass (backdrop-filter) is written as CSS, but its cost actually follows the GPU formula.
So the way to tell isn't "what did I write it with," it's to open the performance panel and see which row that stutter actually lands on. This echoes the earlier point: find problems by measuring, not by guessing.
Lossless & Lossy Optimization
Whether on the CPU or the GPU, optimization falls into two buckets, lossless and lossy. Lossless: the visuals stay exactly the same, you just simplify or remove work that wasn't needed. Lossy: you make an effect simpler or drop it entirely, trading visuals for performance.
Do all your lossless optimization first, and treat lossy as the last resort.
Once you've caught the root cause, the fix is often easy. But plenty of times you can't fix it, maybe because of hardware limits or compatibility issues. In that case, besides solving the problem directly, you can hand devices that can't keep up a simplified version, which is called degrading, essentially doing lossy optimization on lower-end devices.
For example, the same effect runs fine on a computer but freezes on a phone, so on the phone you degrade it to a simpler version. That's a perfectly valid way to solve a performance problem too.
My Own Story
Those concepts get a lot more concrete with the portfolio I'm building.
This portfolio has quite a few WebGL effects. It ran smooth on my desktop, but on an old laptop it stuttered badly and clearly needed optimizing.
To solve a problem you have to define it first, so instead of rushing to cut effects, I measured. The result didn't match my guess at all. I'd assumed the biggest hog was the flashiest crystal on the screen, but it wasn't, because it only covers a small patch of screen. The real performance hog was the tunnel background filling the entire screen. It looks understated, but because it covers so much screen and so many pixels, it was the biggest source of cost.
But the background is the effect itself, and hacking it out would lose the whole mood, so I wanted to look elsewhere. I noticed the three footer buttons had always carried a layer of frosted-glass blur. A blur has to recompute everything behind it (meaning every frame it has to resample and blur all over again), and behind those buttons was that tunnel moving every frame, so the browser was redoing this expensive area on every single frame. Once I removed the blur, performance jumped. And since the background was already dark, that blur was barely visible anyway, so removing it made almost no visual difference. That's a textbook lossless optimization: delete the redundant per-frame work, the visuals stay the same, and the performance comes back.
Wrapping Up
Performance optimization is a way of thinking.
Locate first, then find a direction. Find problems by measuring, not by guessing. Your eyes can fool you, but the numbers you measure won't. And before you start, make sure the problem reproduces reliably.
Know the framework and you'll know where you can slack off. The framework of a creative website: the DOM/CSS render chain (later is cheaper, don't repeat work, keep the scope small), and WebGL pixels (fewer pixels, simpler per pixel, fewer repaints).
Try lossless first, keep lossy as the last resort. On devices that can't keep up, you can degrade.
At the end of the day, the heart of optimization is this: be lazy! Wherever your code can slack off, let it.
Further Reading
- Rendering performance — web.dev
- CSS Triggers — which changes trigger which stage
- Making Software: Shaders
- Jake Archibald on the browser event loop, rAF, and setTimeout
Glossary
- rAF (requestAnimationFrame): tells the browser "run this once, right before the next frame is painted." Used to collapse frequent events into one-per-frame, or to drive continuous animation.
- FPS (Frames per second): how many times the screen updates per second. 60fps = about 16.7ms per frame, and dropping below that starts to feel janky.
- CPU: handles DOM/CSS rendering (Style/Layout/Paint), sequential, one thing done well at a time.
- GPU: handles WebGL/shaders, thousands of cores processing huge numbers of pixels in parallel.
- Retina: a high-pixel-density screen with twice the pixels on each side (about four times total), where fullscreen effects cost more.
- shader: a small program that runs "once per pixel" on the GPU.
- layout thrashing: the trap of repeatedly "change layout → read position" within one frame, forcing the browser to recompute layout many times.