Blade Edits Leave Production Unstyled When CSS Lacks New Classes
A CSS file that loads with 200 does not necessarily contain what the page needs. Tailwind includes only the classes it sees at build time. Upload blade files without rebuilding, and the page gets correct HTML paired with CSS that does not recognize it.
1-minute summary
- Symptom / problem
- The production dashboard has no colors or buttons and icons stack vertically, although the CSS loads with 200
- Who should read
- People using Tailwind with Laravel blade who deploy by uploading only the blade files
- Fix in short
- The served bundle was built before the new classes were written. Prove it with one grep, put the build step in the deploy script, and use a safelist for both v3 and v4
A user of a web app I maintain sent me a screenshot of the production dashboard, with menu tiles stacked vertically, no card backgrounds, a login button that was no longer blue, and text in the browser's default font, as if the page had no CSS at all. Worse, I could not say how long it had looked like that, because I always viewed this app on my dev machine with vite dev running. Everything looked normal on my machine.
This app runs Laravel 12 with Vite and Tailwind v3, hosted under a sub-path on a shared host. The domain names, filenames, and paths in this article are all examples, but the file sizes and troubleshooting sequence are real.
Symptoms: CSS loads with 200, but the page looks unstyled
What made this take time was that nothing showed an error anywhere. I opened the Network tab in DevTools: no 404, the CSS file returned 200, and its size was not zero. The Console tab was empty. Laravel's logs were quiet. The returned HTML contained every class written in blade.
I did not know the last two numbers when I started investigating. If I had known from the start that the entire app's bundle was only 35 KB, this would have been over much sooner.
My first three guesses were wrong
First, I blamed caching, because "works on my machine, broken for the user" sounded exactly like a cache problem. I cleared the browser cache, worked through the CDN cache, and reopened the page. It was still bare. I have covered all five deployment cache layers in Deployed, but the site is not updating, but this case was different: clearing any number of layers would not fix it, because the file being served really was the latest file. It just did not contain what the page needed.
Second, I blamed Laravel's view cache, thinking an old compiled blade template was still in use. I ran php artisan view:clear, but that did not fix it either. Thinking it through, this contradicted the evidence from the start: the output HTML already contained all the new classes, which meant the new blade template was in use.
Third, I suspected the asset path, because the app lived under a sub-path and I had seen assets lose their prefix before. This was the quickest theory to rule out, because the CSS file actually loaded. If the path were wrong, I would have seen a 404.
Each asked, "Has the correct file reached the browser?" when the evidence already said it had. The question I should have asked from the first minute was does the file that arrived contain rules for the classes this page uses? One command could answer that.
The decisive check: grep for a class in the CSS actually served
I downloaded the CSS file referenced by the page and checked for a class used by the login button.
# ดูว่าหน้าเว็บอ้าง CSS ไฟล์ไหน
curl -sS https://example.com/app/login | grep -o 'build/assets/app-[^"]*\.css'
# build/assets/app-XXXX.css
# นับ class ที่หน้าใช้ ในไฟล์ที่เสิร์ฟจริง
curl -sS https://example.com/app/build/assets/app-XXXX.css | grep -c 'bg-blue-600'
# 0
# ขนาดไฟล์
curl -sS https://example.com/app/build/assets/app-XXXX.css | wc -c
# ประมาณ 35000
The result was 0. The minified file was a single line, so grep -c could only return 0 or 1, but that was enough to settle it. I checked several more classes and got the same result for all of them. The file was missing bg-blue-600, grid-cols-4, bg-gradient-to-br, rounded-xl, and almost the entire slate color set. That matched every detail in the user's screenshot: without a grid, the tiles stacked vertically; without a background color, the button was plain.
If you prefer checking in the browser, select the element and open the Computed tab. If the property that the class should set is completely absent, and the Styles tab has no rule for that class, even a crossed-out one, the rule is missing from the CSS, rather than being overridden. These are two different problems with different fixes.
How it works: JIT includes only classes seen at build time
Tailwind does not ship every possible class. At build time, it scans the files specified in content in tailwind.config.js and generates rules only for the classes found in those files at that moment. Classes added to blade afterward cannot appear in the bundle until the next build.
Looking back at how I deployed this app, there were two paths. The normal path was a deploy script on the server, which at the time only ran composer, migrate, cache generation, queue:restart, and an opcache reset. There was no build step. The other path was a hot-fix where I uploaded blade files directly with scp. Both paths could deliver new blade files, but neither created a new bundle.
Another thing I had misunderstood was thinking that content-hashed filenames would prevent this. The hash only helps with browser caching. It changes only when a new build runs. If nobody builds, manifest.json still points to the same file, and @vite still inserts a link to that file. Everything is doing its job correctly; the file it points to is simply older than the blade template.
The same mechanism explains why I could not say how long the page had been bare. I edited blade and saw the result on my dev machine, which kept rescanning. No step required me to open the production page in a real browser after deployment, and the deployment itself had no step that could fail over this, because it had no concept of a build. This kind of mistake could therefore persist until a user sent me a screenshot.
The new file exists but is not being served
The file on disk is correct. Some layer is holding an old copy. Clearing the right layer fixes it. grep finds the class in the file on disk.
The new file has never been built
The file being served is the latest one that actually exists. Clearing any number of cache layers will not fix it. grep returns 0 everywhere. Rebuilding is the only fix.
Fix it, then add a build step to the deploy script
The immediate fix was to run a build on the server.
cd /home/webuser/app
npm install
npm run build
php artisan view:clear
# ยืนยันด้วยตัวตรวจเดิม
ls -l public/build/assets/*.css
grep -c 'bg-blue-600' public/build/assets/app-*.css
# 1
The new bundle was 62 KB, with all the missing classes restored. I opened the dashboard again: the tiles formed a four-column grid, and the button was blue again. I did not touch a single line of blade.
The more important part was preventing a repeat. I added a build step to the server's deploy script as step 2.5, after migrate and before cache generation.
#!/usr/bin/env bash
set -euo pipefail
cd "$APP_DIR"
# 1) dependency ฝั่ง PHP
composer install --no-dev --optimize-autoloader
# 2) ฐานข้อมูล
php artisan migrate --force
# 2.5) build asset -- ขั้นที่เคยไม่มี
npm install
npm run build
# 3) cache และ worker
php artisan config:cache
php artisan view:cache
php artisan queue:restart
# 4) ด่านตรวจ: bundle ต้องไม่เล็กผิดปกติ และต้องมี class ที่หน้าใช้จริง
CSS=$(ls -t public/build/assets/app-*.css | head -1)
SIZE=$(wc -c < "$CSS")
[ "$SIZE" -ge 50000 ] || echo "[WARN] $CSS มีแค่ $SIZE ไบต์ น้อยผิดปกติ"
grep -q 'bg-blue-600' "$CSS" || { echo "[ERR] bundle ไม่มี bg-blue-600"; exit 1; }
echo "[OK] $CSS $SIZE ไบต์"
The 50 KB threshold is a rough check I use for this app: if the actual app's bundle falls below roughly that size, I treat it as suspicious. Other apps will have different numbers. If you use this approach, record the size of a known-good build as a baseline and set your threshold from that.
The other rule I took away was that a hot-fix uploaded with scp must always be followed by a build if the uploaded file is blade. Later, I added a new set of auth pages, which confirmed this rule again: I needed both route:cache and npm run build. Without the first, I got a 404; without the second, I got an unstyled page.
Tailwind v4: the same problem, but safelists move into CSS
Another site I run uses Laravel 12 with Tailwind v4 and Vite 7 on a shared host, deployed by uploading files individually. I do not build on the server or rebuild after every blade edit. I edited the navigation file, adding me-auto and ml-auto to push the language switcher to the right. I uploaded only the blade file, and the layout did not move at all.
Even this time, I still started by clearing caches: the CDN, the browser, and the view cache, before remembering the same command.
curl -s https://example.com/build/assets/app-XXXX.css | grep -c '\.me-auto'
# 0 = ไม่มี class นี้ใน CSS
The class was present in the rendered HTML, but the built file contained no .me-auto, and the Computed tab did not show that property. The footer's social buttons, which used arbitrary color values, had the same problem. There are three levels of fixes. I used the first that day; the other two were work I still needed to follow through on.
- Urgent: inline style Write
style="margin-inline-end:auto"directly on the element. It works without depending on the bundle. I used this first that day to make the page look correct immediately. - Proper fix: build and upload the whole folder Run
npm run buildon the dev machine, then upload the entirepublic/build/folder, includingmanifest.json, because the hashed filenames change on every build. Upload only the CSS file without the manifest, and the page will still point to the old file. - Prevention: safelist Force classes you know you will use to be generated every time, whether the scanner finds them in the source or not.
The third option is where v4 differs most clearly from v3. v4 no longer supports the old safelist in tailwind.config.js. Declare it in the main CSS file instead.
/* resources/css/app.css (Tailwind v4) */
@import "tailwindcss";
/* บังคับสร้าง utility กลุ่มนี้เสมอ */
@source inline("{me-auto,ml-auto,mr-auto,ms-auto}");
/* หรือเขียนกฎเองตรง ๆ ก็ได้ผลเท่ากัน */
.me-auto { margin-inline-end: auto; }
v3 still uses safelist in the config as before.
// tailwind.config.js (Tailwind v3)
module.exports = {
content: ['./resources/views/**/*.blade.php', './resources/js/**/*.js'],
safelist: [
'me-auto', 'ms-auto',
{ pattern: /^bg-(green|amber|red)-(100|600)$/ },
],
};
I often see three groups of classes go missing this way. The first is logical properties such as me-* and ms-*, which I use infrequently, so they tend to be new classes in the project each time. The second is arbitrary values in square brackets, such as bg-[#1877F2] or w-[42px]. Each value is a separate class, and every one must appear in the source at build time. The third and worst is class names assembled from variables.
{{-- ตัวสแกนเห็นแค่ข้อความ "bg-" กับตัวแปร ไม่เห็นชื่อ class เต็ม build กี่รอบก็ไม่ได้ --}}
<span class="bg-{{ $color }}-600 text-white">{{ $label }}</span>
{{-- เขียนชื่อเต็มไว้ใน map ตัวสแกนอ่านเจอทุกตัว --}}
@php
$badge = [
'paid' => 'bg-green-600 text-white',
'pending' => 'bg-amber-600 text-white',
'failed' => 'bg-red-600 text-white',
];
@endphp
<span class="{{ $badge[$status] ?? 'bg-slate-600 text-white' }}">{{ $label }}</span>
Rebuilding fixes the first two groups. No number of builds fixes the third, because the full name never appears in the source. I prefer writing a map of full class names over using a safelist, because reading the code immediately tells me which colors the page uses. But if the colors really come from a database, use a safelist as needed.
An option for machines without a pipeline: compile a single file
Another job involved an internal server with no pipeline at all. The page originally loaded Tailwind from a CDN along with an external font. I removed both external dependencies and compiled a single file to keep in public.
npx [email protected] -c tailwind.config.js \
-i resources/css/app.css -o public/app.css --minify
# ได้ไฟล์ประมาณ 19 KB แล้ว deploy ไฟล์นั้นขึ้นไปพร้อม blade
This approach requires no Node on the server, no manifest, and no hash, but the trap is exactly the same. After changing classes in blade, I must recompile and upload app.css as well. And because the filename does not change, browser caching becomes another layer to watch. A version query string should be appended when referencing the file.
Vite's dev mode and Tailwind's watch mode rescan whenever a file changes, so new classes work immediately on my machine. This kind of mistake will therefore never show up on the dev machine. I have to check the file that production actually serves.
Post-deployment checklist
| What to check | Method | Passes when |
|---|---|---|
| Bundle size | wc -c on the file the manifest points to |
Not suspiciously smaller than the previous build |
| One new class | curl ... | grep -c |
Returns 1 |
| Assembled classes | Search for class="...-{{ in blade |
None found, or already in the safelist |
| Live page | Open in a browser on a machine other than the dev machine | Layout matches dev |
So when I encounter a production page that looks unstyled even though the file loads, I no longer start with caches. I start by using grep to check for one class in the file actually being served. If it returns 0, there is nothing to clear; I can go straight to building. If it returns 1, I go back and work through the cache layers in order. This one command eliminates half the wrong paths from the first minute. If your deploy script still has no build step, take a look at it today. If I have left anything out or made a typo, I will come back and correct it later.
Want us to set this up?
Get help with server setup, configuration, migration, or troubleshooting. Save time for the work that matters.
Hit something like this? Stuck somewhere?
Come trade notes on the LinuxThai board



Comments 0
No comments yet — be the first