Assets vs Public for static videos
-
20-12-2019 - |
Question
I have a static video in my rails application. I have two copies of it: one stored in assets/videos
and one stored in public
. For some reason the video stored in the assets
folder loads much slower than the video stored in the public
folder.
- Does anyone know why?
- What is the best practice? Is it bad practice to put it in
public
?
Solution
Does anyone know why?
Because public
folder is the first place which serves incoming request. If the folder/file doesn't found in that folder, it will be forwarded to rails.
What is the best practice? Is it bad practice to put it in public?
it depends. If you want to use rails features like accessing videos folder with assets_path
or may be like converting videos from one format to two with some rails script or you want restrict videos to some countries or people/user then you should put NOT put in public
folder.
That's all.
OTHER TIPS
The assets directory is only needed if you want to take advantage of the asset pipeline. The asset pipeline handles things from compressing and compiling .coffee and .less or sass files to compressing your js and css into one file so your webserver only has to serve one file for each.
When you compile your assets with the "rake task bundle exec rake assets:precompile" they are moved to your public directory anyhow
Check this comment https://stackoverflow.com/a/8581316/1231365
So it's better to keep your videos in the public folder.