Skip to content

Commit 6a519a1

Browse files
author
Your Name
committed
fix: Force Netlify cache clear to resolve JavaScript chunk 404 errors
- Update .netlify-rebuild file with new timestamp - Add NETLIFY_CACHE_FIX.md with detailed troubleshooting guide - Document root cause: Build cache mismatch causing old chunk references - Provide step-by-step solution for clearing all caches Issue: JavaScript chunks returning 404 because Netlify is serving cached build with old chunk references. New build generates different chunk hashes but cache still points to old chunks. Solution: Clear Netlify build cache via dashboard, then clear service worker and browser caches.
1 parent 3a09764 commit 6a519a1

3 files changed

Lines changed: 157 additions & 1 deletion

File tree

.netlify-rebuild

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# Force clean build
1+
# Force clean build - Updated 2026-02-27 14:30
2+
# Build ID: 3a09764
3+
# This forces Netlify to clear cache and rebuild from scratch

NETLIFY_CACHE_FIX.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Netlify Cache Issue - JavaScript Chunk 404 Errors
2+
3+
## Problem
4+
You're seeing errors like:
5+
```
6+
GET https://codeex-ai.netlify.app/_next/static/chunks/fd37fa83-2fca480fd0fc6fa6.js net::ERR_ABORTED 404
7+
Refused to execute script because its MIME type ('text/html') is not executable
8+
```
9+
10+
## Root Cause
11+
Netlify is serving an old cached build. The JavaScript chunks from the previous build don't match the current deployment. This happens when:
12+
1. Build cache contains old chunk references
13+
2. Service worker cached old chunk URLs
14+
3. Browser cached old HTML with old chunk references
15+
16+
## Solution: Force Complete Cache Clear
17+
18+
### Step 1: Clear Netlify Build Cache (REQUIRED)
19+
20+
**Option A: Using Netlify UI (Recommended)**
21+
1. Go to https://app.netlify.com/
22+
2. Select your site: **codeex-ai**
23+
3. Go to **Site settings****Build & deploy****Build settings**
24+
4. Scroll down and click **Clear cache and retry deploy**
25+
5. Wait for the new build to complete
26+
27+
**Option B: Using Netlify CLI**
28+
```bash
29+
netlify build --clear-cache
30+
netlify deploy --prod
31+
```
32+
33+
### Step 2: Clear Service Worker Cache (REQUIRED)
34+
35+
After the new build is deployed, users need to clear their service worker cache:
36+
37+
**For You (Developer):**
38+
1. Open https://codeex-ai.netlify.app in Chrome
39+
2. Press F12 to open DevTools
40+
3. Go to **Application** tab
41+
4. Click **Service Workers** in left sidebar
42+
5. Click **Unregister** next to your service worker
43+
6. Go to **Storage** in left sidebar
44+
7. Click **Clear site data**
45+
8. Hard refresh: Ctrl+Shift+R (Windows) or Cmd+Shift+R (Mac)
46+
47+
**For Users:**
48+
They'll need to do the same, or you can add a version check to force service worker update.
49+
50+
### Step 3: Verify the Fix
51+
52+
1. Open https://codeex-ai.netlify.app in an incognito window
53+
2. Open DevTools (F12) → Network tab
54+
3. Refresh the page
55+
4. Check that all JavaScript chunks load with 200 status (not 404)
56+
5. Try navigating to different pages
57+
6. Check console for errors
58+
59+
## Alternative: Add Service Worker Version Check
60+
61+
To automatically force service worker updates, we can add a version check. This will help prevent this issue in the future.
62+
63+
### Update Service Worker Configuration
64+
65+
Add this to your `next.config.js` in the PWA workboxOptions:
66+
67+
```javascript
68+
workboxOptions: {
69+
// ... existing options
70+
buildId: process.env.BUILD_ID || Date.now().toString(),
71+
}
72+
```
73+
74+
This will force the service worker to update when the build ID changes.
75+
76+
## Prevention: Best Practices
77+
78+
### 1. Always Clear Cache on Major Updates
79+
When you make significant changes (like we did), always clear Netlify cache:
80+
```bash
81+
# Before deploying
82+
git commit -m "Major update"
83+
git push origin main
84+
85+
# Then in Netlify UI: Clear cache and retry deploy
86+
```
87+
88+
### 2. Use Build IDs
89+
Netlify automatically generates build IDs, but we can make them more explicit:
90+
91+
In `netlify.toml`, add:
92+
```toml
93+
[build.environment]
94+
BUILD_ID = "${COMMIT_REF}"
95+
```
96+
97+
### 3. Service Worker Update Strategy
98+
Consider adding a "New version available" notification to prompt users to refresh.
99+
100+
## Current Status
101+
102+
- ✅ Code pushed to GitHub (commit: 3a09764)
103+
-`.netlify-rebuild` file updated to force cache clear
104+
- ⚠️ **ACTION REQUIRED:** Clear Netlify build cache (see Step 1 above)
105+
- ⚠️ **ACTION REQUIRED:** Clear browser/service worker cache (see Step 2 above)
106+
107+
## Quick Fix Commands
108+
109+
```bash
110+
# 1. Update the rebuild trigger file (already done)
111+
echo "# Force rebuild $(date)" > .netlify-rebuild
112+
113+
# 2. Commit and push
114+
git add .netlify-rebuild
115+
git commit -m "Force Netlify cache clear"
116+
git push origin main
117+
118+
# 3. Then go to Netlify UI and click "Clear cache and retry deploy"
119+
```
120+
121+
## Why This Happens
122+
123+
Next.js generates unique chunk names based on content hashes. When you:
124+
1. Build locally → generates chunks like `4241-876245a25c4c5b5d.js`
125+
2. Deploy to Netlify → Netlify caches the build
126+
3. Make changes and deploy again → generates NEW chunks like `4241-abc123def456.js`
127+
4. But Netlify cache still references OLD chunks
128+
5. Browser tries to load old chunks → 404 error
129+
130+
The solution is to clear ALL caches (Netlify build cache, service worker cache, browser cache).
131+
132+
## Testing After Fix
133+
134+
Once you've cleared all caches and redeployed:
135+
136+
```bash
137+
# Test in incognito mode
138+
# 1. Open https://codeex-ai.netlify.app
139+
# 2. Check console for errors
140+
# 3. Navigate to different pages
141+
# 4. Try AI chat
142+
# 5. Check TTS functionality
143+
```
144+
145+
All JavaScript chunks should load successfully with 200 status codes.
146+
147+
---
148+
149+
**Next Steps:**
150+
1. Go to Netlify dashboard
151+
2. Click "Clear cache and retry deploy"
152+
3. Wait for build to complete
153+
4. Test in incognito window
154+
5. If still issues, clear service worker cache (Step 2)

QUICK_START_DEPLOYMENT.md

Whitespace-only changes.

0 commit comments

Comments
 (0)