脚本和样式表与插件的文件夹结构
我很好奇构建数据的最佳实践/最有效的方法。
选项
所有脚本都放在脚本文件夹中,所有样式表都放在 css 文件夹中。
此方法的问题在于,依赖于样式表的插件不会位于同一目录中,并且在将脚本添加到页面时可能会被忽略通过 jQuery 否定动态地将样式添加到插件脚本需要外部样式表。
使用此方法的音乐会是通过 jQuery 与样式表加载样式的开销将脚本、样式表和插件单独放入单独的文件夹中,并让插件脚本动态加载样式表。
对此方法的担忧是它可能等于或大于前一种方法的开销
我不确定选项 2 和 2 的开销。 3,但是它们将是最干净/首选的方法。
我计划记录使用自定义插件的过程,但是我想防止站点过多和未来的混乱,但需要保持较低的开销。
I am curious as to the best practices/most efficient way to structure my data.
options
All scripts go in scripts folder, all stylesheets go in css folder.
concerns with this method is that plugins that are dependent on a stylesheet would not be in the same directory and could be overlooked when adding the script to a pageDynamically add styles to plugin script via jQuery negating the need for the external stylesheet.
concerts with this method is the overhead loading styles via jQuery vs. stylesheetSeparate scripts, stylesheets, and plugins into separate folders and have the plugins script dynamically load the stylesheet.
concerns with this method is that it's possibly equal to, or greater than the overhead of the previous method
I'm unsure of the overhead on options 2 & 3, they would be the cleanest/preferred methods however.
I plan on documenting the process on using the custom plugins, however I want to prevent over-site and future confusion but need to maintain low overhead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最近写了一篇文章,详细介绍了我的文件夹设置,该设置基于 4 个顶级文件夹的孤立结构:
这样做的原因是基于 3 个主要标准的关注点分离:
核心原则是通过 /vendor 和 /assets 将第 3 方代码与项目代码分离。
任何应该分层的代码(例如主题、增强功能、猴子补丁)都应该放在 /assets/vendor 中。
因此,您的自定义层次结构为:
它不会解决您关于加载资源方式的问题,但它将提供有关如何加载资源的结构。 >管理您的资产。
更多信息和示例请参见:http://www.davestewart.co.uk/blog/项目结构/
I recently wrote a post detailing my folder setup, which is based on a siloed structure of 4 top-level folders:
The reason for this is separation of concerns, based on 3 main criteria:
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:
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/
选项
正确。标准化所有路径以适应此结构。
浏览器有缓存是有原因的。这破坏了缓存的能力。
不要动态加载样式表。参见#2。
options
Correct. Normalize all paths to suit this structure.
Browser have a cache for a reason. This breaks the ability to cache.
Don't load stylesheets dynamically. See #2.
我个人使用这种类型的文件夹结构,因为它清楚地定义了我必须管理的代码与我使用但不管理的代码。
Personally I use this type of folder structure, because it clearly defines the code I must manage versus the code I use but do not manage.