你的Web应用程序结构的最佳实践的提示是什么? [英] What are your tips for best practice for web application structure?

查看:120
本文介绍了你的Web应用程序结构的最佳实践的提示是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工作中做了很多自定义应用程序。我试图为新的应用程序定义一些标准。有点像Elements。



CSS :如何组织样式表?我应该有一个基本样式表为整个网站和每个单独的页面定制?我应该有另一个打印样式吗?我听说链接更多的文件需要更多的时间,浏览器检索它们。 (每页更多的对象...也有很多的javascript文件或图像的问题)...有多少是太多?你大量评论你的CSS吗?提供任何嵌套结构?在元素内按字母顺序排列?我需要复位吗?进口怎么样?和排版?



Javascript :基本上相同的问题。 Javascript文件...我应该包括一个或两个好的库(例如JQuery和Prototype),然后为每个页面包含另一个?现在我突然包括5或6个CSS和JS文件...



目录结构:如何组织网站?目前,我使用类似

  / CSS ...对于CSS文件
/ JS ...对于javascript文件
/ INC ...对于私人代码包括
/ ASSETS / IMG ...对于图像
/ ASSETS / AU ...对于音频
/ ASSETS / SWF ...对于Flash

此外,欢迎任何其他提示。谢谢!

解决方案


我应该有一个基本样式表为整个网站,个人页面?


务实。如果你有足够的规则,你可以在一个文件中组织它们,并保持监督什么是什么,这样做。如果你有大量的规则只适用于你的网站中的某些部分或单独的页面,通过所有的方式将它们分成自己的子样式表,但不觉得需要为每个页面创建单独的样式表即使它只包含两条​​规则。向< body>添加网页特定的类或ID,以便您可以从共享的样式表中挑选单个网页。



是为了您的利益作为作者,所以做你最容易管理的。对于一个复杂的网站,它可能是多个CSS文件,但它不会是几十个。


打印样式?


一般是。虽然您可以使用@media规则将打印样式嵌入到另一个样式表中,但这在传统上是错误的,因此将媒体置于< link>标记中通常是最简单的。在任何情况下,打印样式表通常与屏幕对应方不同,因此保持其规则分开是有意义的。



是的,但是这种效果往往被夸大了。 HTTP / 1.1通过在客户端和服务器之间保持连接来减少每个请求的延迟,这是一个强大的缓解。


是太多?


足够你不太可能有这么多样式表。脚本可以是一个问题,如果你使用那种框架,每个类需要一个脚本文件,否则一般都OK。


您是否对CSS有大量评论?




浅评论通常应该足够了。 CSS的声明性规则样式通常不会变得复杂到需要深入解释代码可以需求。


在元素内按字母顺序排列?




除非这样更容易管理。通常情况下,您不会尝试分组类似的规则或适用于相似元素组的规则。


重启?


完全重置?如果您知道自己正在做什么,并且可以选择要重置的特定问题默认值,则不需要。


库(例如JQuery和Prototype)


不要包含多个框架,除非你绝对需要。




如果每个页面有特定的自定义行为,你可以。但这通常不会发生。如果你使渐进增强行为脚本绑定到eg。类名,您可以在每个使用它的页面上包含每个行为的脚本,然后让它自动查找要绑定的元素。


目录结构:如何组织网站?


对我的Python / WSGI应用程序:

  appfolder 
application.py - 主WSGI入口点和控制/配置脚本
data - 运行时可写应用程序文件存储
private - 通过Web服务器不可用的文件
public - 作为Web服务器上的虚拟目录安装
logs - 访问,错误,应用程序日志文件
系统 - 所有静态应用程序代码和数据
htdocs - web服务器根文件夹
文件 - 静态可执行文件
img - 静态图像
脚本 - JavaScript
style - CSS
lib - Python站点使用的模块
appmodule - 主应用程序代码包
模板 - HTML页面模板
电子邮件文本模板

对我来说,将'data'保存在'system'中的应用程序的单独位置(具有单独的权限)很重要。你需要能够换出'system'文件夹来升级应用程序,而不必担心在htdocs / img中有上传的图像,你必须担心保存。


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!!

解决方案

Should I have one base style sheet for the whole site and one for each individual page for customizations?

Be pragmatic. If you have few enough rules that you can organise them all in one file and retain an oversight of what does what, do that. If you have a significant number of rules that only apply to certain sections or individual pages in your site, by all means break them out into their own sub-stylesheets, but don't feel the need to create a separate stylesheet for every single page even when it only contains two rules. Add a page-specific class or id to <body> so you can pick out single pages from a shared stylesheet should you need to.

The separation of styles into stylesheets is for your benefit as an author, so do what you find easiest to manage. For a complicated site that'll probably be more than one CSS file, but it's not going to be dozens.

Should I have another for print styles?

Generally yes. Whilst you can embed print styles inside another stylesheet using an @media rule, this has traditionally been buggy, so putting the media in the <link> tag is usually easiest. In any case print stylesheets are often so different from their screen counterparts that it just makes sense to keep their rules separate.

I've heard that linking more files takes more time for the browser to retrieve them.

Yes, but this effect is often overstated. HTTP/1.1 reduces the per-request latency by keeping connections between the client and server alive, which is a strong mitigation.

How many is is too many?

Enough that you're extremely unlikely to have that many stylesheets. Scripts can be a problem if you're using the kind of framework that demands one script file per class, but otherwise are generally OK. It's more commonly problematic with lots of small images.

Do you heavily comment your CSS?

Light commenting usually should be enough. CSS's declarative rule style doesn't usually get complicated enough to need the in-depth explanations code can demand. In particular though, document anything counterintuitive like browser-specific hacks.

Alphabetize within elements?

Not unless that makes it easier for you to manage. Usually it wouldn't, you'd try to group similar rules, or rules applying to similar groups of elements.

Do I need a reset?

A full reset? Not if you know what you're doing and can select the particular problematic defaults you want to reset.

Should I include one or two nice libraries (JQuery and Prototype, for example)

Don't include more than one framework unless you absolutely have to.

and then have another included for each page?

If each page has particular custom behaviour you could. But that doesn't usually happen. If you make progressive-enhancement behaviour scripts that bind to eg. class names, you can include the script for each behaviour on each page that uses it, then let it find the elements to bind to automatically.

Directory Structure: How do you organize a site?

Personally, for my Python/WSGI applications:

appfolder
    application.py       - main WSGI entry point and control/configuration script
    data                 - run-time writable application file store
        private          - files not available through the web server
        public           - mounted as a virtual directory on the web server
    logs                 - access, error, application log files
    system               - all the static application code and data
        htdocs           - web server root folder
            file         - static servable files
            img          - static images
            script       - JavaScript
            style        - CSS
        lib              - Python modules used by site
            appmodule    - main application code package
        templates        - HTML page templates
            mail         - mail text templates

It's important for me to keep the ‘data’ in a separate place (with separate permissions) to the application in ‘system’. You need to be able to swap out the ‘system’ folder to upgrade the application, without having to worry that there are uploaded images in htdocs/img you have to worry about keeping.

这篇关于你的Web应用程序结构的最佳实践的提示是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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