Skip to content
A global perspective on digital financeAbout The Token Press
CRYPTO. FINANCE. WHAT’S NEXT.The Token PressYour daily briefing ↗

Beginner · 6 min read

AI Website Works in Preview but Shows 404 on Refresh?

Trace page, asset and API requests to diagnose a broken deployment. Use a small routing exercise and a focused AI repair prompt while preserving working URLs.

The Token Press education desk · Updated

Learning path: Build with AI: ChatGPT, Astra, Gemini and a Practical Learning Path →

Why clicking a link and refreshing can give different results

A page can work after you click a menu link and still fail when someone opens its address directly. In a client-routed single-page application, JavaScript may change the view and browser history without asking the server for a new HTML document. Refreshing the page creates a different test: can the host serve that address from a fresh request?

MDN documents that pushState changes the history entry without immediately loading its new URL. This explains one common mismatch, but it does not prove every blank page is a routing problem. A missing script, wrong deployment directory or failing API can produce a similar-looking result.

This guide is for diagnosing your own AI-assisted website or a permitted test deployment. AI did not create a separate kind of web hosting: identify the framework and host before choosing a repair. A static site, client-routed app and server-rendered application may need different deployment settings.

Collect one failed request before asking for a rewrite

Save the failing URL, deployment version, time and exact action. Compare clicking an internal link, opening the same URL in a new signed-out window, and refreshing there. Use fictional records if a page normally contains private customer data.

In the browser's Network panel, identify the main document request and then any failed scripts, styles or API requests. Record the requested path, HTTP status and response type. A document 404, a JavaScript file 404 and an API 404 are different failures, even when all three leave the reader on an unusable screen.

A 200 response is not sufficient by itself. A request for a JavaScript module that receives the site's HTML page has received the wrong resource. Likewise, a JSON API receiving HTML has not become healthy because the server returned success. Inspect the response type and a non-sensitive excerpt, rather than copying cookies or authorization headers into an AI chat.

If the host shows a deployment error or the main page returns a server error, address that evidence first. Repeatedly changing headings, deleting routes or replacing the whole application makes a narrow fault harder to isolate.

Check the build, deployment folder and base path

Vite's static-deployment documentation uses a production build and, by default, a dist output directory; that directory can be configured differently. Its preview command is for checking the build locally, not running a production server. Confirm the actual host published the output from the intended commit.

A nested address such as /workshop/ needs consistent asset locations. Vite's base setting adjusts supported asset references during the build. That is separate from the application's route configuration: React Router's BrowserRouter, for example, has an application basename setting. Changing one does not prove the other matches.

Compare an actual script path in the built HTML with the uploaded file. If the browser requests /assets/site.js but the file was published at /workshop/assets/site.js, establish which base path the project intends. Do not move a working public page just to make an incorrect asset reference appear valid.

Also compare old and newly opened tabs. Vite describes how an older page can reference a chunk removed by a later deployment. That clue calls for reviewing the release and cache strategy. Clearing one browser's cache can be a diagnostic step, but it does not demonstrate that every visitor will receive a coherent release.

Use a host-specific route repair, not a universal catch-all

For a static client-routed app, the host may need to serve its entry HTML for a valid application route while preserving the requested URL. Netlify calls a rule with status 200 a rewrite. Its documentation explains SPA fallbacks, rule order and the default protection for existing files.

A deliberately narrow Netlify teaching example is the _redirects line: /workshop/agenda /workshop/index.html 200. It assumes this exact agenda route exists in the app and the target file exists in the deployed output. It does not configure the client router, fix missing assets or apply automatically to another host.

Use the deployment method for your actual framework. A server-rendered page may require its server runtime or host adapter; a generated static page may need its own emitted HTML. Do not replace API routes, authentication handlers or every missing file with the home page.

Test unknown URLs as well as valid ones. Google recommends meaningful HTTP status codes and explains how client-routed error pages can become soft 404s. Preserve a genuine not-found response where your architecture supports it; follow the documented error strategy when it does not. A blanket 200 response can hide an error rather than fix it.

Worked example: diagnose three deployment observations

Our fictional workshop site is intended to live under /workshop/. Observation A: the menu opens /workshop/agenda, but a fresh document request to that address returns 404. Its existing JavaScript and CSS load correctly. The evidence points toward direct-route handling; it does not justify renaming the agenda page.

Observation B comes from a separate test build. The main document loads, but it requests /assets/site.js, which returns 404. The release contains /workshop/assets/site.js. Check the build's intended base and published directory. Adding only an agenda fallback would leave this missing asset unresolved.

Observation C follows an over-broad repair. A deliberately nonexistent /workshop/missing-test page and a missing JavaScript URL both return the home page with status 200. The repair has concealed two failures. The valid agenda route needs a usable entry document; nonexistent pages and absent assets need appropriate error behavior.

Write one expected result for each observation, then repeat the same request after the proposed fix. In Case A, confirm the agenda URL remains in the address bar and the agenda content appears on a direct visit and refresh. In Case B, confirm the returned resource is JavaScript from the intended release. In Case C, confirm the missing resources no longer masquerade as successful home-page responses.

These cases are an original diagnostic exercise, not evidence that a particular host was tested or that your website has the same fault. If a request trace contradicts the proposed explanation, revise the explanation before applying a configuration change.

Visual explainerFind the request that failed
Case ADocument 404The menu works; a fresh agenda request fails. Check direct-route handling.
Case BAsset 404The script is under another base path. Compare the build with the deployed files.
Case CWrong body, status 200Missing pages and scripts receive home-page HTML. Narrow the fallback.
Check the requested resource, status and response type together.Original fictional deployment worksheet. These are diagnostic examples, not a test of a hosting account.

Give the AI a bounded repair prompt

Example prompt: The fictional site uses a static client-routed build under /workshop/. An internal link reaches /workshop/agenda, but a fresh document request returns 404. The release's existing assets return the correct file types. Inspect the build output, router base and host rules. Propose the smallest supported repair and show the changed files. Preserve public URLs, page text, titles, descriptions, canonicals, existing redirects and intentional noindex rules.

Continue the prompt: Verify direct visits, refresh, back/forward navigation, asset responses and a deliberately nonexistent path. Keep API and authentication routes outside any page fallback. State which checks were run and which are only proposed. Do not publish or claim success from a local preview alone.

Supply relevant redacted configuration and request evidence rather than an entire account export. Ask the tool to identify uncertainty explicitly: which server handled the request, which build was served, and whether the reported failure occurs before or after the app starts.

Review the diff against the last working version. A routing repair should have a reason for every changed rule. Unrelated redesigns, mass redirects and newly disabled security controls are not evidence that the reported page-loading fault was fixed.

Verify the published result and keep a rollback point

Build and check the proposed version, deploy it through the established process, and confirm the public deployment identifier. Test the clean public address while signed out. A route working only in a development server or only after a prior navigation is not the finished result.

Compare the existing page's title, description, canonical and indexing rules with the saved baseline. Check ordinary links and form behavior too. This is a protection check, not a promise that a configuration repair will change rankings or traffic.

Keep the last working release and record which hosting configuration changed alongside the application. If a repair affects both layers, rolling back only the frontend may leave the faulty routing rule in place. Restore only the relevant change while preserving subsequent unrelated work.

  • The intended release is actually deployed.
  • Valid page URLs work on a direct visit and refresh.
  • Scripts, styles and API responses have the expected content type.
  • Unknown pages and missing files retain appropriate error behavior.
  • Existing URLs, metadata and intentional indexing rules match the baseline.
  • The release record distinguishes executed checks from suggested checks.

Sources & further reading

Educational content. Examples are illustrative. Protocols, products and rules can change; consult the linked documentation for current details.

Explore the newsroom

Connect what you have learned with the latest reporting.