To be clear, I'm not looking for opinions but rather facts based on actual in-the-field usage of different file structure types.
In researching, before asking this questions, I've seen many posts about what the right folder structure is for a web application. For example, I'll see someone list where the following should go: css, js, html, images, php. But, I haven't seen anyone go into much deptch about what the static directory structure should look like.
I have a lot of images in form of static/images/mustang_2017_front.jpg
using Ford vehicles for example. Is it best to keep them in this flat file format or use a hierarchical folder structure such as static/images/mustang/2017/front.jpg
. All the images are the same type for each car (e.g front, side, rear, top). Also, though I'm asking about images, I think the naming conventions standards apply to static files in general.
Option 1- flat
static/images/mustang_2017_front.jpg
static/images/mustang_2017_side.jpg
static/images/mustang_2017_rear.jpg
static/images/fusion_2017_front.jpg
static/images/fusion_2017_side.jpg
static/images/fusion_2017_rear.jpg
Option 2- hierarchical
static/images/mustang/2017/front.jpg
static/images/mustang/2017/side.jpg
static/images/mustang/2017/rear.jpg
static/images/fusion/2017/front.jpg
static/images/fusion/2017/side.jpg
static/images/fusion/2017/rear.jpg
Here are some of the benefits I can think of for each approach, but they're from a human perspective. Is one of the options easier to work with in code? Does it matter much? I just don't want to be setting myself up for something that's not scalable in the future.
Option 1- flat Benefits
- all files have all information in the name
Option 2- hierarchical Benefits
- from a human perspective it's easier to manually navigate and find what you're looking for using a hierarchical folder system instead of having a large number of files all in the same folder
To be clear, I'm not looking for opinions but rather facts based on actual in-the-field usage of different file structure types.
It is very much
A.
a matter of opinion andB.
it depends on the actual implementation.How are the files going to be used and by who. If your visitors are going to be downloading images from your site, they might end up with 10x
front.jpg
in their download folder. So for me that is not great. Also whoever is processing the files (e.g. a designer) could have the same name open in e.g. Photoshop and this won't make it clear. So I would say that option 2 isn't great in most cases I can imagine.Option 1 however can result in a massive single folder with thousands of files.
I like stuff being descriptive and clear, to suit most cases. There is an
Option 3
also;static/images/mustang/2017/mustang_2017_front.jpg
. In my opinion this has the best of both worlds. The file name itself is descriptive and your folders are organised. You could easily delete e.g.2015
when it's not used anymore. Also think about if it should bemustang/2017/
or2017/mustang/
for your case