Best directory structure for static files: hierarchical and flat

To be clear, I'm not looking for opinions, but rather facts based on the actual use of different types of files in different types of files.

When researching, before asking these questions, I saw a lot of messages saying that the correct folder structure for the web application. For example, I will see a list of someone where the following should go: css, js, html, images, php. But I have not seen anyone go into much of what should look like a static directory structure.

I have many images in the form of static/images/mustang_2017_front.jpg , for example, using Ford cars. Is it better to keep them in this flat file format or use a hierarchical folder structure such as static/images/mustang/2017/front.jpg . All images are of the same type for each car (for example, front, side, rear, top). Also, although I am asking about images, I think that conventions of conventions 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 that I can come up with for each approach, but they are from a human point of view. Is there one option that is easier to work with in code? . It is important? I just don't want to tune in to something that doesn't scale in the future.

Option 1 - Flat Benefits

  • all files have all the information in the name

Option 2 - Hierarchical Benefits

  • from a human point of view, it’s easier to manually navigate and find what you are looking for using a hierarchical folder system instead of having a large number of files in the same folder.

To be clear, I'm not looking for opinions, but rather facts based on the actual use of different types of files in different types of files.

-one
source share
1 answer

It is very important A. question of opinion and B. it depends on the actual implementation.

How files will be used and by whom. If your visitors are going to download images from your site, they may end up in the 10x front.jpg download folder. So for me it's not great. Also, the one who processes the files (for example, the constructor) may have the same name open, for example. Photoshop, and that won't be clear. Therefore, I would say that option 2 in most cases is small.

Option 1, however, can lead to a massive single folder with thousands of files.

I like that the material is descriptive and understandable in most cases. There is also Option 3 ; static/images/mustang/2017/mustang_2017_front.jpg . In my opinion, this is the best of both worlds. The file name is descriptive and your folders are organized. You can easily delete, for example. 2015 when it is no longer in use. Also consider if it should be mustang/2017/ or 2017/mustang/ for your case

+1
source

All Articles