ASP.Net MVC:集中 CSS 和 JS 依赖项

发布于 2024-09-30 15:38:27 字数 410 浏览 0 评论 0原文

我在 ASP.Net MVC 站点中使用 jQuery 插件。

我经常根据我在每个页面中使用的插件的要求包含 CSS 和 JS 文件。因此,我想将所有这些依赖项集中在我的应用程序中的一个位置。因此,如果给定插件的依赖项发生更改或更新,我只需修改应用程序中的一个位置即可。

我考虑了两种可能的解决方案:

  • 使用部分方法扩展 HTMLHelper 就像 GetPlugin("jqgrid"); 那样 将打印出所有脚本并 需要样式标签。

  • 为每个视图创建一个局部视图 类似插件jqGridDependency.ascx 其中将包含脚本和 需要样式标签。

你还有其他想法吗?您对这两项提案有何看法?

I'm using jQuery plugins in an ASP.Net MVC site.

I've often to include CSS and JS files as required by the plugins I use in every page. So I want to centralize all those dependencies in a single place in my app. thus if a dependency for a given plug-in is changed or updated, I'll only have to modify a single place in my app.

I've thought in two possible solutions:

  • Extend the HTMLHelper with a partial method
    like GetPlugin("jqgrid"); that
    will print out all the script and
    style tags needed.

  • Create a partial view for each
    pluginlike jqGridDependencies.ascx
    that will contain the script and
    style tags needed.

Do you have any other idea? what do you think of both proposals?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满意归宿 2024-10-07 15:38:27

http://combres.codeplex.com/ 可以为您提供一个框架吗?

我个人对这种方法的唯一反对意见是,每个单独的页面都会有一个独特的 JavaScript/CSS 文件,就好像您将所有内容组合并压缩为一个,然后简单地使用类和事件来触发 JavaScript 增强功能,并在需要时您的网站将运行一个快得多。

Could http://combres.codeplex.com/ provide you with a framework for this.

My only personal objection to this method is that each individual pages will have a unique JavaScript/CSS file where as if you combined and compressed everything into one and simply used classes and events to trigger the JavaScript enhancements as and when needed your site would run a lot faster.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文