Directory structure for a website (js/css/img folders)

Posted by nightcoder on Pro Webmasters See other posts from Pro Webmasters or by nightcoder
Published on 2012-12-17T17:08:02Z Indexed on 2012/12/17 17:14 UTC
Read the original article Hit count: 826

For years I've been using the following directory structure for my websites:

<root>
  ->js
    ->jquery.js
    ->tooltip.js
    ->someplugin.js
  ->css
    ->styles.css
    ->someplugin.css
  ->images
    -> all website images...

it seemed perfectly fine to me until I began to use different 3rd-party components.
For example, today I've downloaded a datetime picker javascript component that looks for its images in the same directory where its css file is located (css file contains urls like "url('calendar.png')").

So now I have 3 options:

1) put datepicker.css into my css directory and put its images along. I don't really like this option because I will have both css and image files inside the css directory and it is weird. Also I might meet files from different components with the same name, such as 2 different components, which link to background.png from their css files. I will have to fix those name collisions (by renaming one of the files and editing the corresponding file that contains the link).

2) put datepicker.css into my css directory, put its images into the images directory and edit datepicker.css to look for the images in the images directory. This option is ok but I have to spend some time to edit 3rd-party components to fit them to my site structure. Again, name collisions may occur here (as described in the previous option) and I will have to fix them.

3) put datepicker.js, datepicker.css and its images into a separate directory, let's say /3rdParty/datepicker/ and place the files as it was intended by the author (i.e., for example, /3rdParty/datepicker/css/datepicker.css, /3rdParty/datepicker/css/something.png, etc.). Now I begin to think that this option is the most correct.

Experienced web developers, what do you recommend?

© Pro Webmasters or respective owner

Related posts about web-development

Related posts about css