I already put the folder named assets in my public folder and I should be able to access the assets like described on this page: https://laravel.com/docs/9.x/helpers#method-asset
But for some reason It wont load and the browser console gives this error:
Loading failed for the “http://localhost:8000/assets/js/jquery-3.4.1.min.js” when this should be the exact path
In the blade file I wrote this:
<script src="{{asset ('assets/js/jquery-3.4.1.min.js') }}"></script>
I already tried with URL::asset and It doesnt find the file
I made the symbolic link 'links' => [ public_path('storage') => storage_path('app/public'),
The real path of the file is /home/penta/ponti-gest/storage/app/public/assets/js
In my page I am using http
Based on your comments:
I already have the folder assets in my public/storage folder
#GiuseppeP. Is the public/storage folder a symbolic link?
yes I made the symbolic link 'links' => [ public_path('storage') =>
storage_path('app/public'), ],
Your file is in the storage path.
This is accessible by using:
storage_path()
The storage_path function returns the fully qualified path to your
application's storage directory. You may also use the storage_path
function to generate a fully qualified path to a given file within the
storage directory:
storage_path('app/public/assets/js/jquery-3.4.1.min.js')
Addendum
Alternatively, you can use the asset() helper by prefixing the path with storage/.... I.e:
The Public Disk
The public disk included in your application's filesystems
configuration file is intended for files that are going to be publicly
accessible. By default, the public disk uses the local driver and
stores its files in storage/app/public.
Once a file has been stored and the symbolic link has been created,
you can create a URL to the files using the asset helper:
asset('storage/assets/js/jquery-3.4.1.min.js')
method asset() meaning go inside public folder
so if it doesn't work
<script src="{{asset ('assets/js/jquery-3.4.1.min.js') }}"></script>
you should have in public folder assets folder then js folder
then the file jquery-3.4.1.min.js
hopefully that help you
you must set ASSET_URL in your .env file.
then run
php artisan config:cache
Related
Does Vite support adding a folder and its content into the final product? (Adding a folder in the dist directory)
If so, then how can I do it?
See Vite's documentation on assets:
The public Directory
If you have assets that are:
Never referenced in source code (e.g. robots.txt)
Must retain the exact same file name (without hashing)
...or you simply don't want to have to import an asset first just to get its URL
Then you can place the asset in a special public directory under
your project root. Assets in this directory will be served at root
path / during dev, and copied to the root of the dist directory
as-is.
The directory defaults to <root>/public, but can be configured via
the publicDir option.
Note that:
You should always reference public assets using root absolute path - for example, public/icon.png should be referenced in source code as /icon.png.
Assets in public cannot be imported from JavaScript.
If you move your files to the public directory, they will be included in the build. You can also configure the publicDir option to include a different folder, if you can't use the public folder.
I'm currently using Meteor and trying to learn more about the framework. In the documentation about special directories the following is said about the public/ special directory:
All files inside a top-level directory called public/ are served as-is to the client. When referencing these assets, do not include public/ in the URL, write the URL as if they were all in the top level. For example, reference public/bg.png as <img src='/bg.png' />. This is the best place for favicon.ico, robots.txt, and similar files.
My question is: since I refer to files inside of public/ directory as if they were located in the root folder of my application, what's the different between putting the files in the public/ folder and in the root folder? Or is it just for organization sake?
Also the documentation I quoted above makes some examples using assets (some pngs and favicon.ico) and no JavaScript or HTML files. Am I able to put some JavaScript code in there and then import them in another file by referencing as if this code was located in the root of my app? Or is the public/ directory somewhat made only for assets?
I failed to find any docs that explains what is done to files inside this directory in detail (I only found what I quoted above). So if any documentation of that kind is available it would help a lot!
My question is: since I refer to files inside of public/ directory as if they were located in the root folder of my application, what's the different between putting the files in the public/ folder and in the root folder? Or is it just for organization sake?
Just because you can reference or "import" a file from public/ doesn't mean it functions in the same way to how a normal file import would work. Files located in public gets served as is without being minified/run through the Meteor pipleline. Second, these files are accessible to the client which makes sense given how'd import them without preceding slashes and keep them mostly to serve stuff like favicon and what not.
So in a sense, such files within public are made available within relation to your client bundle/code whilst not being a part of them, get it?
This way of serving assets isn't unique to Meteor, even React has a public directory.
Also the documentation I quoted above makes some examples using assets (some pngs and favicon.ico) and no JavaScript or HTML files. Am I able to put some JavaScript code in there and then import them in another file by referencing as if this code was located in the root of my app? Or is the public/ directory somewhat made only for assets?
AFAIK, you can have files of any type in public but since
It's served as is to the client, meaning it's exposed to the public
It doesn't get minified (i.e being part of the final application build code)
You're advised to not have any of the application code within this directory.
The Public folder is how you serve your static files, when you put a file in your root folder it will not be sent to the client by default and you can't use it in your css, when you put that file (say an image) in your public folder you can use it from the css and refer to it as if it was in your root folder, so if I put a.jpg in the public folder I can use url(/a.jpg) in my css, that won't work if a.jpg is simply in your root folder, that's what the docs mean when they say it's served as if it was the root folder.
unlike in Rails, Meteor initiatives don’t have a rigid document structure and you are quite a whole lot free to prepare your projects as you want. a few folder names but have unique which means, and documents within them will be dealt with in a different way.
consumer
files here will be loaded at the client simplest. files in that folder don’t need things like Meteor.isClient.
server
Loaded on the server best, duh! No need for Meteor.isServer whilst files are in that folder, the client won’t see these files.
public
This directory is for property like photographs. on your initiatives, you reference stuff in the public folder as if they have been in the root folder. as an example, when you have a report: public/nude.jpg, then for your app you include it with .
personal
files only available at the server facet thru the assets API.
checks
documents in there received’t be loaded anywhere and are used for checking out your app.
lib
documents in that folder are loaded earlier than whatever else, which makes it the best listing to vicinity the distinct libraries used on a undertaking.
I am trying to create a file uploader which will store file in stored_images directory as shown below:
/project
/bin
/stored_images
/routes
/public
After the file has been saved here, I want to send url of the saved file to my front-end javascript. How can I get the url of file in stored in stored_images directory?? Or is there other better way to do this??
First tell express where to look for static files.
app.use(express.static('public'))
Then put you images folder in your public folder. Then the url to your images would be the path from within the public folder to your images.
For example /my_images/cool_pic.
Using Laravel 5.3
I realized now the view files are under a folder called resources and there's an assets folder which has js folder in it.
public folder still exists
I have read a few other posts saying it's up to you either I want to put my js or css under public or assets
I also know that when using gulp files are directed under public which is changeable.
I am wondering if I put my files under the assets then compile under public do I have to run the compile each time when I test my scripts? If not, what should I put as the src in my html?
You should put it in your public folder. If you use URL::asset('path/to/file') it will return [...]app/public/path/to/file and not the resources path as well.
The resources folder you mentioned is more for raw assets like SASS, LESS, etc.
I have created Dynamic web project and it has .html, .css and .js files. I group these file in respective folders like .js file in javascripts folder and .html file in views folder but i don't able to access these file in project. I used eclipse IDE for this. Is there need to configure path for these folder?
You need to put the JSP file in /index.jsp instead of in /WEB-INF/jsp/index.jsp. This way the whole servlet is superflous by the way.
WebContent
|-- META-INF
|-- WEB-INF
| -- web.xml
-- index.jsp
If you're absolutely positive that you need to invoke a servlet this strange way, then you should map it on an URL pattern of /index.jsp instead of /index. You only need to change it to get the request dispatcher from request instead of from config and get rid of the whole init() method.
These are not Java source files, so it makes no sense to configure them as such. By default in a Dynamic Web Project you only see the src folder under Java Resources. Other folders will be listed at the bottom of the tree. This is by design.
Or if you meant, that you do not see them when you move into the folder by an external file manager: press F5 on the project.
Its based on from which file you are trying to access those files.
If it is in the same folder where your working project file is, then you can use just the file name. no need of path.
If it is in the another folder which is under the same parent folder of your working project file then you can use location like in the following /javascript/sample.js
In your example if you are trying to access your js file from your html file you can use the following location
../javascript/sample.js
the prefix../ will go to the parent folder of the file(Folder upward journey)
I got answer to my question...
Now my directory structure is
WebContent
--javascripts
--stylesheets
--viwes
--META-INF
--WEB-INF
Note: view contain html files
To change path of my welcome html file i made bit change in web.xml present in WEB-INFfolder.
<welcome-file-list>
<welcome-file>/views/welcome.html</welcome-file>
</welcome-file-list>