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

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

Open
xumix opened this issue Apr 27, 2016 · 11 comments

Comments

@xumix
Copy link

xumix commented Apr 27, 2016

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

@xumix xumix changed the title Autobundler does not work in case ScriptResourceLinks() in master page and AddScriptResources in a view page Autobundler does not work in case ScriptResourceLinks() in master page and AddScriptResources in a view page section Apr 27, 2016
@AlexCuse
Copy link
Collaborator

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 added a commit to xumix/SquishIt that referenced this issue Apr 28, 2016
@xumix xumix mentioned this issue Apr 28, 2016
@xumix
Copy link
Author

xumix commented Apr 28, 2016

Here is the PR with tests: #332

@xumix
Copy link
Author

xumix commented Apr 28, 2016

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Author

xumix commented Apr 28, 2016

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

@AlexCuse
Copy link
Collaborator

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

@AlexCuse
Copy link
Collaborator

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
Copy link
Author

xumix commented Apr 28, 2016

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
Copy link
Author

xumix commented Apr 28, 2016

Moreover, I do need priority for script inclusion in autobundler

@AlexCuse
Copy link
Collaborator

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.

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

2 participants