静态文件的最佳目录结构:层次与平面 [英] Best directory structure for static files: hierarchical vs. flat

查看:331
本文介绍了静态文件的最佳目录结构:层次与平面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要清楚,我不是在寻找意见,而是根据不同文件结构类型的实际使用情况寻找事实。



在研究中,在提出这个问题之前,我看到很多关于web应用程序的文件夹结构的文章。例如,我会看到有人列出以下内容:css,js,html,images,php。但是,我没有看到任何人进一步了解静态目录结构应该是什么样子。



我有很多图像的形式是 static / images / mustang_2017_front.jpg 以福特汽车为例。最好保持这些平面文件格式,或使用分层文件夹结构,如 static / images / mustang / 2017 / front.jpg 。所有图像对于每辆车(例如前,后,后,顶)是相同的。另外,虽然我在问图像,但我认为这个命名约定标准一般适用于静态文件。



选项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



选项2-层次




  • 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



以下是每种方法可以想到的一些好处,但是从人的角度来看, 代码中更容易使用的选项之一?是否很重要?



选项1-平价优惠


$ b我只是不想让自己成为未来可扩展的东西。 $ b

  • 所有文件都有名称中的所有信息



选项2-层次优点




  • 从人的角度来看,使用分层文件夹系统手动导航并找到您要查找的内容,而不是大量文件所有在同一个文件夹



要清楚,我不是在寻找意见,

解决方案

这是非常多的 A 一个意见和 B。这取决于实际的实现。



文件将被使用和由谁使用。如果您的访问者将从您的网站下载图像,则他们的下载文件夹中可能会出现10x front.jpg 。所以对我来说不是很好。处理文件(例如设计者)的任何人都可以在例如打印机中打开相同的名称。 Photoshop和这并不清楚。所以我会说,在大多数情况下,我可以想象,选项2不是很好。



然而,选项1可能会导致大量单个文件夹与数千个文件。



我喜欢描述性和清晰的东西,适合大多数情况。还有一个选项3 静态/图像/野马/ 2017 / mustang_2017_front.jpg 。在我看来,这是两个世界最好的。文件名本身是描述性的,您的文件夹是有组织的。您可以轻松删除例如 2015 何时不再使用。
还要考虑一下,如果它是 mustang / 2017 / 2017 / mustang / / p>

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 and B. 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 be mustang/2017/ or 2017/mustang/ for your case

这篇关于静态文件的最佳目录结构:层次与平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆