0

我很好奇构建数据的最佳实践/最有效的方法。

选项

  1. 所有脚本都放在脚本文件夹中,所有样式表都放在 css 文件夹中。
    这种方法的问题是依赖于样式表的插件不会在同一个目录中,并且在将脚本添加到页面时可能会被忽略

  2. 通过 jQuery 向插件脚本动态添加样式,无需外部样式表。
    与此方法的音乐会是通过 jQuery 与样式表的开销加载样式

  3. 将脚本、样式表和插件分开到单独的文件夹中,并让插件脚本动态加载样式表。
    这种方法的问题是它可能等于或大于前一种方法的开销

我不确定选项 2 和 3 的开销,但是它们将是最干净/首选的方法。

我计划记录使用自定义插件的过程,但是我想防止过度现场和未来的混乱,但需要保持低开销。

4

3 回答 3

2

选项

1 - 所有脚本都放在脚本文件夹中,所有样式表都放在 css 文件夹中......

正确的。规范化所有路径以适应此结构。

2 - 通过 jQuery 为插件脚本动态添加样式,无需外部样式表。与此方法的音乐会是通过 jQuery 与样式表的开销加载样式

浏览器有缓存是有原因的。这破坏了缓存的能力。

3 - 将脚本、样式表和插件分开到单独的文件夹中,并让插件脚本动态加载样式表。这种方法的问题是它可能等于或大于前一种方法的开销

不要动态加载样式表。见#2。

于 2011-04-06T20:36:41.577 回答
1

我个人使用这种类型的文件夹结构,因为它清楚地定义了我必须管理的代码与我使用但不管理的代码。

Content
   scripts
     //scripts you created
   css
     //css you create
   images
     // images you created
   frameworks
     jQuery
     jQueryUI
     Other Plugins
于 2011-04-06T20:32:39.227 回答
0

I recently wrote a post detailing my folder setup, which is based on a siloed structure of 4 top-level folders:

/assets
/content
/resources
/vendor

The reason for this is separation of concerns, based on 3 main criteria:

  • what is the content type?
  • who is responsible for the content?
  • how often the content will be updated?

The core tenet is separating 3rd-party code from project code through /vendor and /assets.

Any code that should be layered between (e.g. themes, enhancements, monkey-patches) should go in /assets/vendor.

Therefore your customisation hierarchy is:

  • /vendor
  • /assets/vendor
  • /assets/[resource type]

It won't solve your questions about the way to load assets, but it will provide structure on how you manage your assets.

More info and examples here: http://www.davestewart.co.uk/blog/project-structuring/

于 2014-04-11T11:45:24.057 回答