惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
V
Visual Studio Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
L
LangChain Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
P
Proofpoint News Feed
博客园_首页
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Check Point Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Vite Cold Start White Screen? A Plugin Shows Resource Loa...
dev-zuo · 2026-05-10 · via DEV Community

dev-zuo

TL;DR

White screen ✅ A plugin show progress
vite dev server white screen vite-plugin-white-screen-progress with plugin show progress

Background and Motivation

In daily Vue app development, as the project become more and more complex and the number of components grows, the white screen time of the Vite dev server gradually lengthens, especially during the first load.

vite dev server white screen

Usually, we need to open Chrome DevTools and go to the Nework tab to see the loading progress. But some times, we don't want to open DevTools.

Is there a way to show the loading progress of Vite dev server resources directly on the page?

So I wrote a plugin to resolve this problem.

Usage

Install vite-plugin-white-screen-progress

npm install vite-plugin-white-screen-progress@latest --save-dev --save-exact

Enter fullscreen mode Exit fullscreen mode

Edit vite.config.js, the plugin is enabled only in the dev server(vite dev)and ignored during vite build

// vite.config.js
import devServerWhiteScreenProgress from 'vite-plugin-white-screen-progress'

export default {
  // ...
  plugins: [
    devServerWhiteScreenProgress(),
  ]
}

Enter fullscreen mode Exit fullscreen mode

Minimal code implementation

Use PerformanceObserver observe resource loading

showViteDevLoadProgress();
function showViteDevLoadProgress() {
  const div = document.createElement("div");
  div.setAttribute("id", "vite-dev-loading");
  div.setAttribute("style", "font-size: 14px;");
  document.body.appendChild(div);
  const observer = new PerformanceObserver((list) => {
    list.getEntries().forEach((entry) => {
      // if (entry.initiatorType === 'script' || entry.name.endsWith('.js')) {
      div.innerHTML = `
            Vite resource loading...<br>
            InitiatorType: ${entry.initiatorType} <br>
            StartTime: ${entry.startTime.toFixed(2)}ms <br>
            Duration: ${entry.duration.toFixed(2)}ms <br>
            TransferSize: ${entry.transferSize} 字节 <br>
            Name:${entry.name}  <br>
        `;
      // }
    });
  });
  observer.observe({ entryTypes: ["resource"] });
  function domContentLoadedCb(event) {
    const el = document.querySelector("#vite-dev-loading");
    if (el) el.remove();
    observer.disconnect();
  }
  document.addEventListener("DOMContentLoaded", domContentLoadedCb);
  window.addEventListener("beforeunload", function (event) {
    window.removeEventListener("DOMContentLoaded", domContentLoadedCb);
  });
}

Enter fullscreen mode Exit fullscreen mode

Vite plugin implementation

source code vite-plugin-white-screen-progress - github

function getClientScript() {
   // PerformanceObserver observe resource loading js
   return 'some script'
}

export default function devServerWhiteScreenProgress() {
    return {
        name: 'vite-plugin-white-screen-progress',
        apply: 'serve', // just enabled in dev server(vite dev),ignore when vite build
        // write custom script into index.html <head> 
        transformIndexHtml(html) {
            return {
                html,
                order: 'pre',
                tags: [
                    {
                        tag: 'script',
                        injectTo: 'head-prepend',
                        attrs: {
                            type: 'module'
                        },
                        children: getClientScript()
                    }
                ]
            };
        }
    };
}

Enter fullscreen mode Exit fullscreen mode

Plugin config custom style support

theme fixed

export default function devServerWhiteScreenProgress(config = {
    theme: 'fixed-simple',
    style: '',
}) {

    const themeStyleConfig = {
        // Default style  fix in right, simple info
        'fixed-simple': 'font-size: 12px;background: rgba(0, 0, 0, .8);color: white; padding: 16px;border-radius: 8px;position:fixed;top: 200px;z-index: 1000000;right: 9px;width:150px;height: auto;overflow:hidden;word-break:break-all;',
        // fix in right, more info 
        'fixed': 'font-size: 12px;background: rgba(0, 0, 0, .8);color: white; padding: 22px;border-radius: 8px;position:fixed;top: 200px;z-index: 1000000;right: 9px;width:300px;height: auto;overflow:hidden;word-break:break-all;',
        // Display in a flat layout on the page
        'normal': 'font-size: 14px;background: #fff;color: #333; padding: 22px;border-radius: 8px;',
    }

    // console.log('themeStyleConfig[config?.theme]', themeStyleConfig[config?.theme])

    return {
        name: 'vite-plugin-white-screen-progress',
        apply: 'serve', // just enabled in dev server(vite dev),ignore when vite build
        // write custom script into index.html <head> 
        transformIndexHtml(html) {
            return {
                html,
                order: 'pre',
                tags: [
                    {
                        tag: 'script',
                        injectTo: 'head-prepend',
                        attrs: {
                            type: 'module'
                        },
                        children: getClientScript({
                            themeStyle: config?.style || themeStyleConfig[config?.theme] || themeStyleConfig['fixed-simple'],
                            theme: config?.theme || 'fixed-simple'
                        })
                    }
                ]
            };
        }
    };
}

Enter fullscreen mode Exit fullscreen mode