Combining CSS and JS in master pages and browsing with SquishIt

How do you implement SquishIt to link Css / Js through View Pages and display it on the main page? I thought I could use a ContentPlaceHolder on the Render part, but there seems to be an odd behavior when it sometimes adds 3 files (1 on the view page and 2 on the main page), but in other cases the file added from the Page view is ignored.

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 the SquishIt static Bundle class, which supports the BundleBuilder in HttpContext.Current.Items.

I am wondering if this was done successfully and how to do it.

+4
source share
2 answers

I think you might miss the css and javascript binding points. If you are going to add css or js files on each view in combination with the files on the main page, then you create a ton of small packages that your user must download every time.

If you don't have a ton (and I mean TON) of Javascript and Css, then you better combine ALL of your css and javascript into the same kit. Thus, the user gets hit by loading it for the first time, and then it is cached.

If you have TON css and javascript, use the named bundle function and create packages for different sections of your site. But the thing is that you want to minimize the number of packages created so that the user does not have to download files.

The only exception is for mobile browsers where they have certain size caching restrictions.

+12
source

You can jump on a ship and try Chirpy: http://chirpy.codeplex.com/

Or you can change the ZController approach according to your fantasies: 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 should probably create smaller, larger packages.

+1
source

Source: https://habr.com/ru/post/1314564/


All Articles