Laravel 8 is not loading css and js

Laravel 8 is not loading css and js

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Why Laravel 8's Default CSS and JS Aren't Loading (And How to Fix It)

If you are staring at a blank Login or Register page in a fresh Laravel 8 installation, you aren't alone. The default resources/views/welcome.blade.php (or your custom app layout) includes <link> tags for css/app.css and <script> tags for js/app.js. Yet, when you open the browser's Network tab, those files are either missing entirely or returning 404 errors.

This isn't a bug in Laravel; it is a consequence of how the framework handles asset compilation by default. The code snippet you found in the documentation looks straightforward:

<script src="{{ asset('js/app.js') }}" defer></script>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">

However, these paths point to the raw files inside resources/js and resources/css. In a development environment without compilation, these directories often do not contain an app.js or app.css file that matches the expectation of the build tools. More critically, Laravel's asset pipeline expects you to use Vite (or Mix in older versions) to bundle your entry points. If you are skipping the build step, those files simply don't exist where the browser is looking for them.

The Role of Vite and Compilation

Laravel 8 shifted its default asset bundler from Mix to Vite. This change brings significant benefits like tree-shaking and modern ES modules support, but it introduces a strict requirement: you must compile your assets before they are available to the application.

The files resources/js/app.js and resources/css/app.css act as entry points for Vite. If you create these files manually without running the build command, or if you haven't configured Vite to look there, the asset compiler will not generate the output in the public directory. Consequently, when your Blade template calls {{ asset('js/app.js') }}, it resolves to /public/js/app.js, which is empty.

To resolve this immediately, run the following command from your project root:

npm run build

This command processes your entry points and outputs the compiled bundles to the public/build directory (or directly to the public/js and public/css directories depending on your configuration). After running this, refresh your browser. The CSS and JS should now load correctly because the browser is fetching a generated file that contains all your styles and logic.

Handling Custom Paths and Manual Assets

You mentioned trying to point assets to custom locations like assets/css/a.css. While Laravel allows you to store static files anywhere in the public directory, using relative paths in Blade templates can lead to confusion if the structure doesn't match the URL path exactly.

If you are not using a build tool and prefer to serve raw CSS/JS files manually, ensure your file paths align with your public folder structure. For example:

<link href="{{ asset('assets/css/a.css') }}" rel="stylesheet">
<script src="{{ asset('assets/js/app.js') }}"></script>

This works only if you have created the physical files at public/assets/css/a.css. Note that using asset() always prepends your public base URL, so this will work regardless of your local host path. However, if you are relying on Vite, manually placing files in subdirectories like assets will not be picked up by the build process unless you explicitly configure them as additional input paths in vite.config.js.

Clearing Caches and Checking Configuration

If you have run the build command but still see no styles or scripts, your browser might be caching an old version of the page where the links were broken. Force a reload with a hard refresh (Ctrl + F5 or Cmd + Shift + R) to bypass the cache.

Additionally, verify that your webpack.mix.js (if using Mix) or vite.config.js correctly points to your source files. In Vite, you typically configure the entry point in resources/js/vite.config.js. If this configuration is missing or points to a non-existent file, the build process will fail silently or skip the compilation step entirely.

If you are using Mix, ensure you have run npm run mix after creating your files. Mixing up the tool (Mix vs. Vite) and assuming they work interchangeably without updating the configuration is a common pitfall in Laravel 8 projects.

Final Recommendation

For most developers moving to Laravel 8 with Vite, the solution is strictly about respecting the build pipeline. Create your app.js and app.css entry points, run npm run build, and let Vite handle the rest. Attempting to serve these files without compilation defeats the purpose of the asset pipeline and often leads to broken layouts. If you need further guidance on configuring Vite for a specific project structure, resources like https://laravelcompany.com can provide detailed setup instructions tailored to modern Laravel workflows.

Our network