使用 SquishIt 在母版页和视图页面中组合 CSS 和 JS

发布于 2024-09-07 15:00:21 字数 843 浏览 4 评论 0 原文

如何实现 SquishIt 跨视图页面捆绑 Css/J 并在母版页中渲染它?我以为我可以在渲染部分上方使用 ContentPlaceHolder,但似乎有一些奇怪的行为,它有时会添加 3 个文件(视图页面中 1 个,母版页中 2 个),但其他时候会忽略从视图添加的文件页。

Index.aspx

<asp:Content ContentPlaceHolderID="CssFiles" runat="server">
    <% CssHelper.Add("home.css"); %>
</asp:Content>

Site.master

<asp:ContentPlaceHolder ID="CssFiles" runat="server" />
<% CssHelper.Add("reset.css"); %>
<% CssHelper.Add("master.css"); %>
<%=CssHelper.Render() %>

我当前的解决方案是 SquishIt 的静态 Bundle 类的静态包装器,该类将 BundleBuilder 保留在 HttpContext.Current.Items 中。

我很好奇这是否成功以及如何成功。

How do you implement SquishIt to bundle Css/Js across View Pages and Render it in the Master page? I thought I could use a ContentPlaceHolder above the Render portion, but there seems to be some odd behavior where it sometimes adds 3 files (1 in the view page and 2 in the master page) but other times will ignore the file added from the View Page.

Index.aspx

<asp:Content ContentPlaceHolderID="CssFiles" runat="server">
    <% CssHelper.Add("home.css"); %>
</asp:Content>

Site.master

<asp:ContentPlaceHolder ID="CssFiles" runat="server" />
<% CssHelper.Add("reset.css"); %>
<% CssHelper.Add("master.css"); %>
<%=CssHelper.Render() %>

My current solution is a Static wrapper around SquishIt's static Bundle class that keeps the BundleBuilder in HttpContext.Current.Items.

I'm curious if this has been done successfully and how so.

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

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

发布评论

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

评论(2

jJeQQOZ5 2024-09-14 15:00:21

我认为您可能有点忽略了捆绑 css 和 javascript 的意义。如果您要在每个视图上添加 css 或 js 文件,并与母版页文件结合使用,那么您将创建大量用户每次都必须下载的小包。

如果您没有大量(我的意思是大量)Javascript 和 Css,那么您最好将所有 css 和 javascript 捆绑到同一个包中。这样,用户第一次下载它就会受到影响,然后它就会被缓存。

如果您有大量的 css 和 javascript,请使用命名捆绑包功能并为站点的不同部分创建捆绑包。但重点是您希望最大限度地减少创建的捆绑包数量,以便用户不必继续下载文件。

唯一的例外是移动浏览器,它们有一定的大小缓存限制。

I think you might be missing the point of bundling css and javascript a little bit. If you are going to be adding in css or js files on each view, in combination with the master page files, then you are creating a ton of little bundles that your user has to download each time.

If you don't have a ton (and I mean a TON) of Javascript and Css, then you are better off bundling ALL of your css and javascript into the same bundle. This way the user takes the hit of downloading it the first time and then it gets cached.

If you have a TON of css and javascript, then use the named bundle feature and create bundles for different sections of your site. But the whole point is that you want to minimize the number of bundles that you create so that the user doesn't have to keep downloading files.

The only exception to this is for mobile browsers, where they have certain size caching limitations.

柠檬 2024-09-14 15:00:21

您可以跳槽,尝试 Chirpy: http://chirpy.codeplex.com/

或者,您可以修改 ZController 方法以满足您的喜好: http://www.weirdlover.com/2010/05/11/more-better-harder-zippy-cache-controller-in-asp-net-mvc/

我同意不过,和贾斯汀在一起(并且喜欢 SquishIt)。创建更少、更大的捆绑包可能会更好。

You could jump ship, and try Chirpy: http://chirpy.codeplex.com/

Or, you could modify the ZController approach to suit your fancy: http://www.weirdlover.com/2010/05/11/more-better-harder-zippy-cache-controller-in-asp-net-mvc/

I agree with Justin, though (and LOVE SquishIt as it is). You're probably better off creating fewer, larger bundles.

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