The Hidden public/hot File in Laravel Mix HMR

📖 2 minutes read

You run npm run hot and Laravel Mix starts a webpack dev server with Hot Module Replacement. Your browser auto-refreshes when you edit Vue components or CSS. Magic. But have you ever wondered how Laravel knows to serve assets from the dev server instead of the compiled files in public/?

The answer is a tiny file you’ve probably never noticed: public/hot.

What public/hot Does

When you run npm run hot, Laravel Mix creates a file at public/hot. It contains the dev server URL — typically http://localhost:8080.

Laravel’s mix() helper checks for this file on every request:

// Simplified version of what mix() does internally
if (file_exists(public_path('hot'))) {
    $devServerUrl = rtrim(file_get_contents(public_path('hot')));
    return $devServerUrl . $path;
}

// No hot file? Serve from mix-manifest.json as normal
return $manifest[$path];

So when public/hot exists, mix('js/app.js') returns http://localhost:8080/js/app.js instead of /js/app.js?id=abc123.

When This Bites You

The classic gotcha: you kill the dev server with Ctrl+C, but the public/hot file doesn’t get cleaned up. Now your app is trying to load assets from a server that doesn’t exist.

# Symptoms: blank page, console full of ERR_CONNECTION_REFUSED
# Fix:
rm public/hot

Add it to your troubleshooting checklist. If assets suddenly stop loading after you were running HMR, check if public/hot is still hanging around.

Why This Matters for Teams

The public/hot file should always be in your .gitignore. If someone accidentally commits it, everyone else’s app will try to load assets from localhost:8080 — which won’t be running on their machines.

# .gitignore
public/hot

Most Laravel projects already have this, but if you bootstrapped your project a long time ago or generated your .gitignore manually, double-check.

It’s a tiny file with a simple job, but understanding it saves you 20 minutes of confused debugging when HMR stops working or your assets vanish after killing the dev server.

Daryle De Silva

VP of Technology

11+ years building and scaling web applications. Writing about what I learn in the trenches.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *