Alex Rivera | Logout

What are your tips for best practice for web application structure?

Asked 2009-02-26T16:30:55.757
24

I do a lot of custom applications at work. I'm trying to define some standards for new applications. Something a little like Elements.

CSS: How do you organize the style sheets? Should I have one base style sheet for the whole site and one for each individual page for customizations? Should I have another for print styles? I've heard that linking more files takes more time for the browser to retrieve them. (More objects per page...also a problem with lots of javascript files or images) ... How many is is too many? Do you heavily comment your CSS? Provide any nested structure? Alphabetize within elements? Do I need a reset? What about imports? And typography?

Javascript: Basically the same question. Javascript files...Should I include one or two nice libraries (JQuery and Prototype, for example) and then have another included for each page? Now I'm suddenly including 5 or 6 CSS and JS files...

Directory Structure: How do you organize a site? Currently, I use something like

/CSS          ... For CSS files
/JS           ... For javascript files
/INC          ... For private code includes
/ASSETS/IMG   ... For images
/ASSETS/AU    ... For audio
/ASSETS/SWF   ... For Flash

Also, any other tips would be welcome. Thanks!!

Edit
Report

2 Answers

2

Do your best to have one style sheet. Linking individual style sheets for individual pages defeats the purpose.

You can inherit other stylesheets in your css by including the following lines at the top of the sheet

@import url('blueprint/screen.css');
@import url('blueprint/styles.css');

in this case I'm inheriting the blueprint css styles then adding my custom styles below that.

In terms of JS libraries I prefer to link 3 files.

The Library, one page with all of the plugins, and finally the page code.

For directory structure I generally have the following:

/_css /_images /_scripts files

but recently I've began to put everything used to make the site look/work the way I want it to in a /_presentation directory... then anything additional like images for blog posts etc would go in /images

Hope this helps.

answered 2009-02-26T16:51:56.470
0

I always try to keep the browser from having to load and interpret CSS rules and JS code that isn't used on the HTML in question. I agree with @bobince that you should only break a page's styles and scripts into a separate file if it's necessary for organization, but if your site is very big at all, you will reach that point.

However since I only build template based sites, I am beginning to wonder why I link to external files at all. For example, if I have a base template the things I put in the head of that template will be applied to all the pages on my site. So why not just put my styles and scripts there?

Two reasons come to mind. First the browser can cache the external file and reuse it on every page that includes it without having to load it all over again. Second designers might not be as comfortable poking around in your templates as they are messing with plain CSS files.

That's all well and good for global styles that apply to every single page in your site, but what about those one-off pages that have some style that isn't shared anywhere else? If you added this style to a globally applied external file you'd increase the initial load time of your site just to have a style that is only used on one page. Further, when you go back to that file months later you will likely have forgotten what those rules were even for.

I suggest that any style rule that is not expressed on every single page should be placed in <style> tags within the sub-template that renders the HTML the rule applies to. This will move the load and complexity from the global stylesheet to the actual page where the styles are needed, and give the rules context so that they can be maintained in the future. If this scares your designer they don't need to be writing CSS anyway. Just tell them to stick to Photoshop and let you do the big-boy work.

answered 2009-02-26T21:15:57.040

Your Answer