POOYAST

Preventing flashes of old UI during a hard refresh

How source-first markup, early theme initialization and animation timing reduce visible UI flashes.

Why the flash happens

If the HTML contains a previous icon or an old layout, the browser can paint it before a script replaces it. Slower networks make this mismatch more visible. Changing the original markup is preferable to covering the whole page with a loading screen.

Render the intended interface first

Put the final SVG, navigation state and accessibility attributes in the HTML. Resolve the saved theme in the head, and ship styles locally. Avoid replacing a correctly rendered control just to attach event listeners.

Animate from a consistent starting state

Start the initial entrance once, and respect prefers-reduced-motion. Keep navigation readable if JavaScript is unavailable. Test slow script loading, cache-disabled reloads and different viewport sizes.

Implementation in this portfolio

The navigation uses a three-dot icon in the static HTML rather than a copy icon that is swapped during initialization. The entrance animation does not restart when the interaction script loads.

References

MDN: prefers-reduced-motion