jetheredge / SquishIt

Lets you *easily* bundle some css and javascript! Check out the Google group if you have questions!
http://groups.google.com/group/squishit
MIT License
459 stars 119 forks source link

Autobundler does not work in case ScriptResourceLinks() in master page and AddScriptResources in a view page section #331

Open xumix opened 8 years ago

xumix commented 8 years ago

What I want to do is: make the scripts rendered in master page, but the file itself added inside arbitrary views. So i have a layout page with a section defined. I add scripts in a view within the section and they are not rendered. If I add scripts outside of the section then they are rendered OK

AlexCuse commented 8 years ago

I haven't looked at this in a long time, and have been considering pulling it from v1.0 (I don't use it, and this is the first its been mentioned other than initial discussions with @syndicatedshannon). I think it might make more sense as an add on package anyway.

If you can upload a project somewhere that will replicate the issue for me I will take a look, but I will not have time to start from scratch.

xumix commented 8 years ago

Here is the PR with tests: https://github.com/jetheredge/SquishIt/pull/332

xumix commented 8 years ago

Autobundler is actually a killer feature and a time-saver. I use it all the time with ClientDependency, but I'm tired of it's tight coupling and minify bugs, so I'm tying to replace it.

AlexCuse commented 8 years ago

Good to know - if thats the case I will keep it, as long as it doesn't get too difficult to maintain. Maybe when v1.0 gets out I will have time to write some documentation.

I'll take a look at the test in the next few days.

AlexCuse commented 8 years ago

I think the problem you're seeing is because anything in the section is not executed until RenderSection is called. If you call that before writing the resource links into the page, eg

<body>
    @RenderBody()
    @RenderSection("JavaScript", false)
    @Html.ScriptResourceLinks()
</body>

then it should work. Let me know what you find out.

xumix commented 8 years ago

Well, this is not an actual workaround since i need @Html.ScriptResourceLinks() exactly before RenderSection()

AlexCuse commented 8 years ago

In that case I think you're going to need to raise the issue with the MVC team :)

AlexCuse commented 8 years ago

Out of curiosity, why do you need them in that order?

It seems counter-intuitive to the way autobundling works - you need to make sure that all of your view content has been rendered to ensure that the complete set of content for the bundle is available.

xumix commented 8 years ago

I add some scripts that must be in the page header for instance, at the same time I have many legacy pages that have those scripts included in the section parts. It works like that with ClientDependency, so there is some way to delay script tag rendering after all the sections have been executed.

xumix commented 8 years ago

Moreover, I do need priority for script inclusion in autobundler

AlexCuse commented 8 years ago

I would review a pull request for Priority, but mostly think that if order matters you should not be using autobundler.

I would not even consider delaying script tag rendering.

It sounds like ClientDependency is able to meet your needs pretty well (possibly because of the tight coupling that you find problematic?). Suggest working with them to figure out any minifier issues you are having.