As someone getting started with web development seeing that web pages themselves and content related to them is on same hierarchy level in folder(directory) structure used for website development is confusing.
Now of course this isn't always the case but seems to be a standard generally used form what i have seen from searching and studying online.And i never found proper explanation when is comes to the part of folder structure this question addresses.
As an example something like this is general folder structure i see being generally used.
But this doesn't make sense to me at first sight.Why would you hierarchically in folder(directory)structure define content related to web pages you should just link to them on the same level as web pages themselves when it only adds additional unnecessary complexity for our purposes. For example using above image having to write from Page.html in pages folder every time you need to refer to any content related to web page ../pages/images/one_big_turtle.jpg instead of simply being able to always access all web page related content folders and content in them form pages folder itself whenever you need said content for anything relating to web pages like so images/one_big_trutle.jpg. To me second is much more simple and makes more sense.
So what is the general reason for organizing things like this? In what scenario is it more advantageous then simply having pages related content in pages folder(directory) itself?
../pages/images/one_big_turtle.jpg
whre the URL stats with a.
. It is almost always better to use site relative links like/images/one_big_turtle.jpg
where the URL starts with a/
. Site relative links tend to be shorter, work from any page on your site, work from all sub-directories, and don't propagate crawl errors such as double slashes.foo.html
should be next to the resources used directly in that page:foo.js
andfoo.css
andfoo.jpg
. There can be valid reasons to create directories, but I'm not a fan of the directory layout pictured in your question.