shammadahmed's avatar

CSS & JS Files Not Being Loaded

Everything works fine if I use a CDN. But when I try to use the elixir() function, it gets output the correct file ( http://localhost:8000/build/css/app-cd08e7f4.css ), But it gives a 404 error on the file ( Same is for JavaScript files ). Here is my view:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="Hammad Ahmed">
    <link rel="icon" href="favicon.ico">

    <title>Socket Switcher</title>

    <link href="{{ elixir('css/app.css') }}" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="container">
      <div class="header clearfix">
        <nav>
          <ul class="nav nav-pills pull-right">
            <li role="presentation" class="active"><a href="#">Home</a></li>
            <li role="presentation"><a href="#">About</a></li>
            <li role="presentation"><a href="#">Contact</a></li>
          </ul>
        </nav>
        <h2 class="text-muted">Socket <small><em>Switcher</em></small></h2>
      </div>

      <div class="jumbotron">

        @include('errors.flash')

        @yield('content')

      </div>

      <footer class="footer">
        <p>© Company {{ date('Y') }}</p>
      </footer>

    </div> <!-- /container -->


    <script src="{{ elixir('js/app.js') }}"></script>
  </body>
</html>

That's my Gulp.js file:


/*
 |--------------------------------------------------------------------------
 | Elixir Asset Management
 |--------------------------------------------------------------------------
 |
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks
 | for your Laravel application. By default, we are compiling the Less
 | file for our application, as well as publishing vendor resources.
 |
 */

var paths = {
    'jquery': 'bower_components/jquery/dist/',
    'bootstrap': 'bower_components/bootstrap/dist/',
    'fontAwesome': 'bower_components/font-awesome/',
    'semanticUi': 'bower_components/semantic-ui/dist/',
}

elixir(function(mix) {
    mix.copy([
            paths.bootstrap + 'fonts/**',
            paths.fontAwesome + 'fonts/**'
        ], 'public/fonts')

        .styles([
            paths.bootstrap + "css/bootstrap.css",
            paths.fontAwesome + "css/font-awesome.css",
            paths.semanticUi + "semantic.css",
        ], 'public/css/app.css', './')

        .scripts([
            paths.jquery + "jquery.js",
            paths.bootstrap + "js/bootstrap.js",
            paths.semanticUi + "semantic.js"
        ], 'public/js/app.js', './')

        .version(["css/app.css", "js/app.js"]);
});
0 likes
20 replies
JeffreyWay's avatar

And you can confirm that the versioned files do exist at that path?

JeffreyWay's avatar

If you're getting a 404 on your local server for that file, it's because it does not exist at that path shown in your view...

shammadahmed's avatar

That's the output from the elixir function <link href="/build/css/app-cd08e7f4.css" rel="stylesheet">

And the file does exists. It's also not working if I provide a manual path.

JeffreyWay's avatar

Not sure what to say. If you're positive that a public/build/css/app-cd08e7f4.css file exists in your project, then I can't explain why you'd get a 404.

RachidLaasri's avatar

Open the HTML source page and click on the CSS link and see if it is pointed to the right path.

shammadahmed's avatar

It says: Not Found The requested resource /build/css/app-cd08e7f4.css was not found on this server.

But it does exists.

RachidLaasri's avatar

Try using the asset() method :

<link href="{ { asset('build/css/app-cd08e7f4.css') } }" rel="stylesheet">
pmall's avatar

Try to find more information about your error and communicate it to us. Without any more information we cant help.

If you try to access something else in the public folder, does it work ?

shammadahmed's avatar

It doesn't work: localhost:8000/css/app.css

But it does works: D:/code/socket/public/css/app.css

pmall's avatar

How is your server configured ? Did you modify the public/.htaccess file or the public/index.php file?

skliche's avatar

@shammadahmed Is the web server's root directory socket or public? Does localhost:8000/public/css/app.css work?

Use this .htaccess file and try again loading a file in your public folder:

DirectoryIndex index.php

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteRule .? %{ENV:BASE}/index.php [L]

</IfModule>
shammadahmed's avatar

Thanks everyone.

I found out the php artisan serve was the issue. All worked fine after started the built-in PHP server.

Buit I don't know why.

1 like
MayZin's avatar

Hi, Do you find to solve the problem of that? I'm also facing with that error. I can link when I run the project with PHP server but it doesn't work with artisan.

Please or to participate in this conversation.