should I use assets folder or public folder? laravel 5.3 - javascript

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.

Related

Colocating Assets and Posts in Astro

Is there any way to colocate markdown files and the assets referenced in those markdown files in a single folder in astro.
What i am looking for is to have a sirectory structure similar to the following:
src/
posts/
post1/
post1.mdx
image1-in-post1.png
image2-in-post1.png
...
This is instead of locating the assets in the public directory and needing to consistently reference back to them.
Unfortunately, Astro does not currently support this type of directory structure. You would need to either store your assets in the public directory and reference them from there or use a third-party service such as Cloudinary to store and manage your assets.

What is the use for the special "public" folder in a Meteor app?

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.

laravel asset() doesnt find assets in public

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

ASP.NET Core + React | Correct way to structure files

What is the correct way to structure files in real life application?
By default, if I'm correct, ASP.NET Core projects files should be structured as:
[Solution]
[Project]
Dependencies
Properties
Controllers
Models
Repositories
wwwroot
Pages
Startup.cs
Program.cs
appsettings.json
For any static file it should be inside a wwwroot folder, right?
But then why creating a ASP.NET Core project with React + redux template makes a folder 'ClientApp' instead of 'wwwroot' and places all react code in there with folders 'src' 'public'?
I know that you can do that and then in startup.cs enable it with 'app.UseSpaStaticFiles();', But why? Is it just to make it simpler or does it have real life benefits? Should I structure my files same way too?
And if I suppose, or can, use with 'wwwroot', how should wwwroot folder look? I know that wwwroot folder suppose to contain all the static files such as css, images and js
wwwroot
css
js
images
Since react is a js library/framework, should all code be inside js folder like this
wwwroot
css
js
src
actions
components
store
...
images
I been trying to find an answer but everywhere everyone has a different answer.
On a side note, also if using scss, or similar, should all the scss be inside css folder or should there be a scss folder inside wwwroot that on compile saves css code inside css folder?

Separate Directory for Static Files produced by Nuxt Js

I have a small question
I need a separate directory for the static files produced by Nuxt Js
By Default Nuxt Js creates one single directory(dist) for all the files
The reason is I am running Django Server as backend and I have to place the static files in a separate directory relative to the template directory
File system
--/templates(HTML Files)
--/static(Static Files)
Suggest me a Nuxt Config to achieve this.
Within the static folder, you can create a new folder where you can put your static files. When you run build, Nuxt simply copies everything that are in the static folder into the dist folder. So now you'll get a separate static folder within dist after a build process completes.
Do the same with your assets folder.

Categories

Resources