Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to bundle in partial views then render in master/layout view #336

Open
brgrz opened this issue Sep 13, 2016 · 10 comments
Open

Add to bundle in partial views then render in master/layout view #336

brgrz opened this issue Sep 13, 2016 · 10 comments

Comments

@brgrz
Copy link

brgrz commented Sep 13, 2016

I can't seem to find an example whether it is possible to add to a bundle in different views across the application then render the bundle in master/layout view.

I tried but the bundle seemed to be empty when rendering.

A step further would be to have named bundles, adding scripts to them,then render them out by name.

@brgrz
Copy link
Author

brgrz commented Sep 13, 2016

I'd be willing to take a shot at implementing it if not supporting - if @AlexCuse could point me in the right direction.

@AlexCuse
Copy link
Collaborator

There is support that @syndicatedshannon added a while back. See the AspNetMvcTest for details, under "Auto-Bundling"

https://github.com/jetheredge/SquishIt/blob/master/SquishItAspNetMvcTest/Views/AutoBundling/Combined.cshtml

The code to support it is in SquishIt.Mvc.

@brgrz
Copy link
Author

brgrz commented Sep 13, 2016

I'll take a look

@syndicatedshannon
Copy link
Contributor

Hey guys. Didn't mean to start something and bail. I transitioned to Angular almost right after I got involved here, but would still be glad to lend a hand if I can. @brgrz , want to chat?

@brgrz
Copy link
Author

brgrz commented Sep 14, 2016

Hey, I don't really know what autobundling feature was all about, I have to look at it but didn't have time yet. Will probably do it on friday. In the meantime, if you could explain what it was about?

@brgrz
Copy link
Author

brgrz commented Sep 14, 2016

Also I see #337 and this one related meaning we could have server side modules which register scripts and styles they need and we'd render them out as needed per current view/module that's active since with HTTP/2 we don't have to bundle anymore (some say it still makes sense to but let's assume for these two issues that we don't bundle anything anymore). So we truly get views that load up only the resources they really need.

@AlexCuse
Copy link
Collaborator

If you look at that view I linked, the two HtmlHelper extension methods are what you are after.

.AddResources adds the various resources, then .ResourceLinks renders them.

You can also use .AddScriptResources / .AddStyleResources and .StyleResourceLinks / .StyleResourceLinks if you want to add/render in different sections of the page. .AddResources routes to the appropriate bundle by file extension.

https://github.com/jetheredge/SquishIt/blob/master/SquishIt.Mvc/HtmlHelperExtensions.cs

@syndicatedshannon this seems to work well just wanted to give you credit for the work. The fact it is not documented is on me 😃

@brgrz
Copy link
Author

brgrz commented Sep 16, 2016

@syndicatedshannon @AlexCuse this seems to do what I am after but it doesn't render minified and hash-stamped files.

Another thing, I am using custom view engine to locate views. My views register resources they require which are commonly placed in the folder right next to them. When I used my own code to render out links, I registered them by also providing ViewVirtualPath to the registration method which then rewrited the href/src accordingly. SquishIt of course currently cannot do that and points them to the root of the site.

This is what it renders (note that the view virtual path actually is there available to SquishIt it just doesn't use it):

<link rel="stylesheet" type="text/css" data-autobundle-declaring-view="~/Plugins/Roswell.Plugins.Calendar/Views/Shared/_PluginLayout.cshtml" href="/roswell/styles/plugin.min.css">

@brgrz
Copy link
Author

brgrz commented Sep 16, 2016

Looking at the Autobundler class I think what I need is a convention in place that would say

when viewPath.startsWith("/plugins") rewrite resource link to "/plugins/PluginName/[resource-link-path]"

As per the above example I'd take the data-autobundle-declaring-view value, strip it down to the plugin root folder and merge it with the hrefvalue getting

href="~/plugins/roswell.plugins.calendar/styles/plugin.min.css"

My question is, should I implement that in the Autobundler class?

@AlexCuse
Copy link
Collaborator

What do you mean "but it doesn't render minified and hash-stamped files." - are you running in debug mode? I would expect release bundle rendering to go through the same pipeline, rendering a single minified, hashed file per bundle.

It sounds like you have a very specialized use case, and probably would want to implement your own auto-bundler. If we can help by adding extensibility points to the existing auto-bundler I am all ears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants