Kaiyichen xp — Visual Designer

For the best experience
Enter Full Screen (F11)

Portfolio®︎

Kaiyichen XP

繁體中文 English 简体中文 한국어 日本語 ภาษาไทย

Making a Web XP Start Faster: Caching, Preloading, and an Import Map Trap

Kaiyi Chen ·

kaiyichen.com runs native ES modules without a bundler. I used CSS bundling, module preloading, deferred analytics, and layered caching, then hit an import map ordering bug that served visitors old code.

kaiyichen.com is a Windows XP running in a browser. There is no bundler: the browser loads native ES modules directly. That makes small deployments quick, but it also means many files and requests can slow down the first boot.

I stopped chasing a single Lighthouse score and worked on request count, module loading, caching, and analytics separately. This is the useful part of that process, including a recent import map trap.

Reduce what blocks the first paint

The front end originally had many CSS files, all of which could delay rendering. I merged them into one file and generated its name from a content hash. When any source changes, the name changes too, so the old file can stay cached for a long time. Relative image paths inside CSS need special handling when the merged file moves.

Fonts should not block the first screen either. The page starts with a system font and switches to the site font after it loads. Avatars use an appropriately sized thumbnail instead of the original media-library image.

Turn module loading from a waterfall into parallel downloads

With native modules, the browser must fetch the entry file and parse it before it knows what to fetch next. Network latency turns that into a chain of round trips.

I use modulepreload for the static imports so the browser can download them in parallel. The list is generated from the module tree instead of maintained by hand. Dynamic import() waits until someone opens the relevant app, so startup does not compete for bandwidth.

Analytics goes in the opposite direction: it is inserted after the page loads and the browser has idle time. Events wait in a queue, so analytics arriving late does not lose them.

Many cache layers are fine if invalidation is clear

The site now has browser caching, Cloudflare, nginx, a service worker, and WordPress object caching. Page caching is limited to logged-out visitors for five minutes. Theme JS, CSS, and image URLs include a modification version, so a changed file gets a new URL.

I added a “Clear cache” button in the admin bar. It changes the version suffix, removes bundled CSS, updates object caches, and asks the host to clear page caches. It does not command every browser to delete its cache; it makes the new resources different URLs.

The service worker cache name also follows the theme version. The worker itself returns no-cache, otherwise the new worker might never arrive.

An import map in the wrong place disables versioning

After changing the bottom of an article page, the live site still showed the old content. The Console showed:

An import map rule for specifier '...' was removed,
as it conflicted with already resolved module specifiers.

The file was deployed. The problem was that HTML emitted modulepreload before the import map. The browser resolved relative imports before it saw the map, then discarded the conflicting rules. Modules fell back to URLs without versions, which had already been cached for a long time.

The fix is simple: put the import map before every modulepreload. This kind of issue may not break the page; it only leaves a warning in the Console. Check the Console after a deployment, not just the pixels.

Lighthouse score is not the same as perceived speed

I first treated the boot logo as LCP. After the page became faster, Lighthouse switched to the welcome text that appeared later. On a site that intentionally simulates a boot sequence, the score and the design’s timing do not always move together.

I now use Lighthouse to find real problems: oversized images, resources loaded too early, and unnecessary render-blocking requests. The final score is not worth removing the boot experience that makes the site feel like a computer.

Web Development