0

I run a local installation of xampp on which a laravel 5.2 app is running. I am trying to include css and js files from the public directory, but none of the content of these files is being loaded.

Laravel finds the files, they are just always empty.

I tried to clear the browser cache and the Laravel cache, but neither worked. I have referenced the files in the following ways:

<script type="text/javascript" src="{{ asset('js/all.js') }}"></script>

OR

<script type="text/javascript" src="/js/all.js"></script>

In both cases the files are loaded, but does not contain anything.

I have tried generating the files through elixir or simply putting them directly in the folder, but still the same result.

Any help is appreciated.

JMBarlach
  • 1
  • 4
  • what happens when you just open them in the browser directly? htttp://mypage.maydomain/js/all.js ? – Frnak Aug 02 '16 at 06:46
  • Donț you get a 404 (when accessing the js)? – ka_lin Aug 02 '16 at 06:50
  • 2
    probably the file itself is empty then – jonju Aug 02 '16 at 06:52
  • Check your htaccess file to ignore (js, jpg, jpeg etc) files from being passed in the Laravel's index page (check out my answer to another question as an example http://stackoverflow.com/questions/28364496/laravel-5-remove-public-from-url/32580688#32580688 ) – ka_lin Aug 02 '16 at 06:53
  • The files is not empty, it has some basic jQuery. But it is not only this files, it is any js or css file referenced. And I do not get a 404 error either. – JMBarlach Aug 02 '16 at 07:01

4 Answers4

0

Try this

<script type="text/javascript" src="{{ url('js/all.js') }}"></script>
paranoid
  • 6,799
  • 19
  • 49
  • 86
0

Try this,

<script type="text/javascript" src="{{ URL::asset('js/all.js') }}"></script>

Here your js directory should be in the laravel's app/public folder and URL::asset() will produce the necessary url for you.

You can refer How to include css and js in Laravel 5 for more info.

Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
  • Tried moving the files to app/public, but still the same result. Even with instead of the other options. – JMBarlach Aug 02 '16 at 07:05
0

Okay, so I didn't exactly solve the issue, but I got around it. Just posting answer for future reference.

I set up a virtual host i xampp to get around the files loading from localhost, like in this example: https://www.codementor.io/php/tutorial/how-to-install-laravel-5-xampp-windows

Afterwards the js and css files load on all the different options presented above. Apparently it is something to do with the .htaccess file in the root, when running from the default folder in xampp.

Thanks for all the suggestions.

JMBarlach
  • 1
  • 4
  • Well that's actually what you are always supposed to do when working with laravel on xampp / localhost sub folders – Frnak Aug 02 '16 at 07:30
0

Have you tried this?

<script src="{{URL::asset('/js/jquery-1.10.2.min.js')}}"> </script>

Make sure that the 'js' folder is inside the 'public' folder of your project.

Rav
  • 1,327
  • 3
  • 18
  • 32