跪拜 Guibai
← All articles
Frontend · Vue.js · Architecture

A Vue Login Page Hits Half-Second Loads with Four Specific Tweaks

By 锋行天下 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

First-screen load time directly impacts user retention, and the gap between a 2-second and a 500-millisecond login page is often a handful of Vite and Nginx settings that cost nothing to apply.

Summary

A production Vue.js login page now loads in milliseconds. The speed comes from a handful of concrete build and server configurations rather than any single magic setting. Route-based lazy loading is the baseline, but the real gains arrive when the Element Plus UI library is switched from a monolithic import to on-demand auto-importing via `unplugin-vue-components`.

Vite's `manualChunks` gets a deliberately minimal configuration: only Vue, vue-router, and Pinia are bundled into a single `vue-core` chunk. Everything else — including the UI library — is left to Vite's automatic code splitting. An earlier attempt that manually isolated `element-plus` into a `ui-vendor` chunk actually hurt performance once dynamic imports were active, so that line was removed.

Server-side, Nginx applies Gzip compression at level 6 for text, JavaScript, JSON, and SVG assets. The author notes that HTTP/2 and a CDN were skipped due to certificate and setup constraints, and image lazy loading was unnecessary for this page.

Takeaways
Route-level lazy loading is the non-negotiable starting point for any Vue SPA.
Replacing a full `element-plus` import with `unplugin-vue-components` auto-importing cuts the initial JavaScript payload dramatically.
Manually bundling `element-plus` into a `ui-vendor` chunk backfires when the library is already dynamically imported — the two strategies conflict.
The final `manualChunks` config isolates only `vue`, `vue-router`, and `pinia` into `vue-core`, letting Vite handle the rest automatically.
Nginx Gzip at compression level 6, with a broad set of MIME types including SVG and JSON, shrinks transfer sizes without measurable CPU cost.
HTTP/2, a CDN, and image lazy loading were consciously deferred because the page had few images and no HTTPS certificate.
Conclusions

Minimalist chunk configuration often beats elaborate manual splitting. Removing a `ui-vendor` chunk improved the result because it stopped fighting Vite's own heuristics.

The interaction between `manualChunks` and on-demand component imports is easy to misconfigure; a chunk that looks sensible in isolation can duplicate or block the tree-shaking the auto-import plugin already provides.

Gzip remains a high-leverage, low-effort optimization even in 2025, especially for text-heavy SPAs where the uncompressed bundle can be deceptively large.

Many performance guides push for HTTP/2 and CDNs upfront, but a plain Nginx server with Gzip and smart bundling already gets a login page into the sub-second range.

Concepts & terms
Route lazy loading
A technique where JavaScript for a page is loaded only when the user navigates to that route, reducing the initial bundle size.
unplugin-vue-components
A Vite plugin that automatically imports Vue components on demand, eliminating the need to manually register them globally or per-file.
manualChunks
A Rollup/Vite output option that lets developers explicitly define which modules get grouped into separate JavaScript files, controlling cache invalidation and parallel loading.
Gzip compression
A server-side method that compresses text-based assets before sending them over the network, often reducing file sizes by 70% or more.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗