Laravel 5.2 - All CSS and JS files in public are empty - javascript

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.

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

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.

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.

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.

Related

Laravel js file not found

I've my Laravel javascript file in public/js folder and it is referred like follows.
<script src="{{ asset('public/js/test.js') }}"></script>
But it is still not found 404.
You shouldn't need to include public in the URL. This should work fine;
<script src="{{ asset('/js/test.js') }}"></script>
What is ASSET_URL value? You can check it in the web developer tool in chrome or firefox. You can configure the asset URL host by setting the ASSET_URL variable in your .env file. This can be useful if you host your assets on an external service like Amazon S3 (https://laravel.com/docs/7.x/helpers#method-asset). For eg
// ASSET_URL=http://example.com/assets
asset('public/js/test.js') //http://example.com/assets/js/test.js
Usually your run your server document root as public folder. Hence, I am guessing that removing the public dir path will solve 404 file not found error i.e change to.
<script src="{{ asset('js/test.js') }}"></script>
Please use instead of as public folder is added Automatically by asset

how to use pdf.js without defining pdf.worker location

I meet a problem when using pdf.js to view pdf. The problem comes from the
PDFJS.workerSrc setting. Is that possible to include the pdf.worker.js in
header, like
<script type="text/javascript" src="./../jsfiles/pdf.worker.js"></script>
and not using
PDFJS.workerSrc = './../jsfiles/pdf.worker.js';
is that possible for that? Thanks a lot.
From the documentation:
In order to bundle all src/ files into two production scripts and build the generic viewer, run:
$ gulp generic
This will generate pdf.js and pdf.worker.js in the build/generic/build/ directory. Both scripts are needed but only pdf.js needs to be included since pdf.worker.js will be loaded by pdf.js. The PDF.js files are large and should be minified for production.
This means that you only need to add the following code:
<script type="text/javascript" src="pdf.js"></script>
Remember that all files generated should located in the same directory as pdf.js

cant load external js file in html

I have tried all answers available but none can solve my problem. I have a html page in which I am drawing svg using js. now I want to store this js in external file and call it (my html and js files are in same folder).
<script src="show1.js"></script> on doing so, my internal js cannot find functions defined in external js and gives 'ReferenceError: DrawLine is not defined'. I even tried using alert in external js to check whether it was being loaded or not, but even alert is not working. is there any settings that i will have to check? kindly help.
My code is really huge. I am posting this snippet instead that shows the internal and external js.
<head>
<script>
//only variables are declared
<script>
</head>
<body>
<script src="show1.js"></script>
<script> drawline(10,10,20,20,'black',4); </script>
</body>
show1.js:
function drawline(x1,y1,x2,y2,c,w)
{
//do stuff
}
Note:these pages are part of django project, and so my html and js are stored in the template folder of the project.
you can use the static file app in django to serve external static files: https://docs.djangoproject.com/en/1.10/ref/contrib/staticfiles/
You can create a folder on you project to host your static assets (with the name static for example), then you need to configure your project to serve static files in the settings
STATIC_ROOT = 'path to your folder/static/'
STATIC_URL = '/static/'
then in your template:
{% load staticfiles %}
<head>
<script>
//only variables are declared
<script>
</head>
<body>
<script src="{% static 'show1.js' %}"></script>
<script> drawline(10,10,20,20,'black',4); </script>
</body>
in development mode, the runserver command will serve your static files. you may want to serve the files directly from the web server in production mode. also settings may vary depending on the django version, you can refer to the documentation of your version for further details.

jangaroo loader index.html file

In the Jangaroo tutorial using Maven it states"include a Jangaroo application script generated by the Maven build process". This should be created in src/main/webapp/index.html, it isn't. Can anyone explain this, or what in the pox.xml is missing?
Thanks
The misunderstanding here is that actually, the Jangaroo application script is generated, not the index.html file.
The idea is that your index.html usually contains custom HTML, e.g. loading your CSS or setting up some context. The only Jangaroo-specific things your HTML code has to do is load the generated joo/jangaroo-application.js script and run the application's main class, using its fully-qualified name (in this example, HelloWorld is in the top-level package):
<script type="text/javascript"
src="joo/jangaroo-application.js"></script>
<script type="text/javascript">
joo.classLoader.run("HelloWorld");
</script>
https://github.com/CoreMedia/jangaroo-tools/wiki/Tutorial-~-Deployment

Where to put JavaScript files in a Symfony2 project?

I have a Symfony2 project and I have some JavaScript code to be executed.
Where should the .js file be stored in the project and how to call this file (instead of putting the entire script in the .twig)?
Put it in web/js, then access it in your html via:
<script src="{{ asset('js/script.js') }}"></script>
or consider using Assetic.

Categories

Resources